File tree Expand file tree Collapse file tree 5 files changed +67
-69
lines changed Expand file tree Collapse file tree 5 files changed +67
-69
lines changed Original file line number Diff line number Diff line change 1- #  Container image that runs your code
2- FROM  alpine:3.10
1+ FROM  golang:1.16-alpine
32
4- #  NOTE: install puppeteer Docker deps
5- #  https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-on-alpine
6- #  Installs latest Chromium (92) package.
7- RUN  apk add --no-cache \
8-       chromium \
9-       nss \
10-       freetype \
11-       harfbuzz \
12-       ca-certificates \
13-       ttf-freefont \
14-       nodejs \
15-       npm
3+ WORKDIR  /app
164
17- #  Tell Puppeteer to skip installing Chrome. We'll be using the installed package.
18- ENV  PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
19-     PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
5+ COPY  go.mod ./
6+ COPY  go.sum ./
207
21- RUN  npm install puppeteer
22- COPY  index.js /index.js
8+ RUN  go mod download
239
24- CMD  ["node" , "/index.js" ]
10+ COPY  *.go ./
11+ 
12+ RUN  go build -o /publish-to-hn
13+ 
14+ CMD  [ "/publish-to-hn"  ]
Original file line number Diff line number Diff line change 1+ module  action-hackernews-post 
2+ 
3+ go  1.17 
4+ 
5+ require  github.com/lukakerr/hkn  v0.0.0-20190218004349-b4aa957c3360  //  indirect
Original file line number Diff line number Diff line change 1+ github.com/lukakerr/hkn  v0.0.0-20190218004349-b4aa957c3360  h1:UbY5nZGTN279+eU7Ld2KimDTS29UzZF7T/4whepdY/I =
2+ github.com/lukakerr/hkn  v0.0.0-20190218004349-b4aa957c3360 /go.mod  h1:/7Z86kh6Q6xub2pdlrDF4SFERHDw3mflKzNOYXD7d4I =
  Load Diff This file was deleted. 
Original file line number Diff line number Diff line change 1+ package  main
2+ 
3+ import  (
4+     "fmt" 
5+     "os" 
6+     "github.com/lukakerr/hkn" 
7+ )
8+ 
9+ func  _main () int  {
10+ 	username  :=  os .Getenv ("INPUT_HN_USERNAME" )
11+ 	password  :=  os .Getenv ("INPUT_HN_PASSWORD" )
12+ 	title  :=  os .Getenv ("INPUT_POST_TITLE" )
13+ 	url  :=  os .Getenv ("INPUT_POST_URL" )
14+ 
15+ 	if  (len (username ) ==  0  ||  len (password ) ==  0 ) {
16+ 		fmt .Println ("No supplied credentials. Provide `username` & `password`" );
17+ 		return  1 
18+ 	}
19+ 
20+ 	if  (len (title ) ==  0  ||  len (url ) ==  0 ) {
21+ 		fmt .Println ("No supplied post. Provide `title` & `url` to post" );
22+ 		return  1 
23+ 	}
24+ 
25+ 	client  :=  hkn .NewClient ()
26+ 	cookie , err  :=  client .Login (username , password )
27+ 
28+ 	if  (err  !=  nil ) {
29+ 		fmt .Println (err )
30+ 		return  1 
31+ 	}
32+ 
33+ 	created , err  :=  client .CreateStoryWithURL (title , url , cookie )
34+ 
35+ 	if  (err  !=  nil ) {
36+ 		fmt .Println (err )
37+ 		return  1 
38+ 	} else  if  (created  ==  false ) {
39+ 		fmt .Println ("Unknown error posting to HN" )
40+ 		return  1 
41+ 	}
42+ 
43+ 	fmt .Println ("Successfully submitted to HN" )
44+ 
45+ 	return  0 
46+ }
47+ 
48+ func  main () {
49+ 	os .Exit (_main ())
50+ }
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments