-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Post to HN using lukakerr/hkn go module (#2)
* post to hn using lukakerr/hkn go module * use the go module, remove index.js
- Loading branch information
Showing
5 changed files
with
67 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,14 @@ | ||
# Container image that runs your code | ||
FROM alpine:3.10 | ||
FROM golang:1.16-alpine | ||
|
||
# NOTE: install puppeteer Docker deps | ||
# https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-on-alpine | ||
# Installs latest Chromium (92) package. | ||
RUN apk add --no-cache \ | ||
chromium \ | ||
nss \ | ||
freetype \ | ||
harfbuzz \ | ||
ca-certificates \ | ||
ttf-freefont \ | ||
nodejs \ | ||
npm | ||
WORKDIR /app | ||
|
||
# Tell Puppeteer to skip installing Chrome. We'll be using the installed package. | ||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \ | ||
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser | ||
COPY go.mod ./ | ||
COPY go.sum ./ | ||
|
||
RUN npm install puppeteer | ||
COPY index.js /index.js | ||
RUN go mod download | ||
|
||
CMD ["node", "/index.js"] | ||
COPY *.go ./ | ||
|
||
RUN go build -o /publish-to-hn | ||
|
||
CMD [ "/publish-to-hn" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module action-hackernews-post | ||
|
||
go 1.17 | ||
|
||
require github.com/lukakerr/hkn v0.0.0-20190218004349-b4aa957c3360 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/lukakerr/hkn v0.0.0-20190218004349-b4aa957c3360 h1:UbY5nZGTN279+eU7Ld2KimDTS29UzZF7T/4whepdY/I= | ||
github.com/lukakerr/hkn v0.0.0-20190218004349-b4aa957c3360/go.mod h1:/7Z86kh6Q6xub2pdlrDF4SFERHDw3mflKzNOYXD7d4I= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"github.com/lukakerr/hkn" | ||
) | ||
|
||
func _main() int { | ||
username := os.Getenv("INPUT_HN_USERNAME") | ||
password := os.Getenv("INPUT_HN_PASSWORD") | ||
title := os.Getenv("INPUT_POST_TITLE") | ||
url := os.Getenv("INPUT_POST_URL") | ||
|
||
if (len(username) == 0 || len(password) == 0) { | ||
fmt.Println("No supplied credentials. Provide `username` & `password`"); | ||
return 1 | ||
} | ||
|
||
if (len(title) == 0 || len(url) == 0) { | ||
fmt.Println("No supplied post. Provide `title` & `url` to post"); | ||
return 1 | ||
} | ||
|
||
client := hkn.NewClient() | ||
cookie, err := client.Login(username, password) | ||
|
||
if (err != nil) { | ||
fmt.Println(err) | ||
return 1 | ||
} | ||
|
||
created, err := client.CreateStoryWithURL(title, url, cookie) | ||
|
||
if (err != nil) { | ||
fmt.Println(err) | ||
return 1 | ||
} else if (created == false) { | ||
fmt.Println("Unknown error posting to HN") | ||
return 1 | ||
} | ||
|
||
fmt.Println("Successfully submitted to HN") | ||
|
||
return 0 | ||
} | ||
|
||
func main() { | ||
os.Exit(_main()) | ||
} |