Skip to content

Commit badc2c8

Browse files
committed
Update GH path from binary
1 parent 1c6f367 commit badc2c8

File tree

6 files changed

+70
-50
lines changed

6 files changed

+70
-50
lines changed

.github/workflows/goaction.yaml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/test.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
on:
2+
push:
3+
branches: [main]
4+
workflow_dispatch:
5+
inputs: {}
6+
jobs:
7+
goaction:
8+
runs-on: ubuntu-latest
9+
steps:
10+
11+
- name: Check out repository
12+
uses: actions/checkout@v2
13+
14+
- name: Download binary test
15+
uses: charlieegan3/fetch-gh-release-binary@main
16+
with:
17+
owner: charlieegan3
18+
repo: airtable-contacts
19+
asset-pattern: Linux_x86_64
20+
install-path: /usr/local/bin/airtable-contacts
21+
verbose: true
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Test binary in path
26+
shell: bash
27+
run: |
28+
airtable-contacts --help

Dockerfile

Lines changed: 0 additions & 11 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# fetch-gh-release-binary
22

3-
GitHub Action generated with [goaction](https://github.com/posener/goaction) to
4-
download binaries from GitHub releases and make them available for use in later
5-
steps.
3+
GitHub Action generated to download binaries from GitHub releases and make them
4+
available for use in later steps.

action.yml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# File generated by github.com/posener/goaction. DO NOT EDIT.
2-
31
name: fetch-gh-release-binary
42
description: |
53
GitHub Action to download binaries from GitHub releases and make them
@@ -27,17 +25,25 @@ inputs:
2725
GITHUB_TOKEN:
2826
required: false
2927
runs:
30-
using: docker
31-
image: Dockerfile
32-
env:
33-
GITHUB_TOKEN: "${{ inputs.GITHUB_TOKEN }}"
34-
args:
35-
- "-owner=${{ inputs.owner }}"
36-
- "-repo=${{ inputs.repo }}"
37-
- "-version=${{ inputs.version }}"
38-
- "-asset-pattern=${{ inputs.asset-pattern }}"
39-
- "-install-path=${{ inputs.install-path }}"
40-
- "-verbose=${{ inputs.verbose }}"
28+
using: "composite"
29+
steps:
30+
- run: |
31+
32+
curl -LO https://github.com/charlieegan3/airtable-contacts/releases/download/0.7.0/airtable-contacts_0.7.0_Linux_x86_64.tar.gz
33+
tar -zxf airtable-contacts_0.7.0_Linux_x86_64.tar.gz
34+
md5sum ./airtable-contacts
35+
36+
37+
go run main.go \
38+
"-owner=${{ inputs.owner }}" \
39+
"-repo=${{ inputs.repo }}" \
40+
"-version=${{ inputs.version }}" \
41+
"-asset-pattern=${{ inputs.asset-pattern }}" \
42+
"-install-path=${{ inputs.install-path }}" \
43+
"-verbose=${{ inputs.verbose }}"
44+
45+
md5sum /usr/local/bin/airtable-contacts
46+
shell: bash
4147
branding:
4248
icon: arrow-down-circle
4349
color: orange

main.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var installPath = flag.String("install-path", "", "Where to put the installed bi
2626
var verbose = flag.Bool("verbose", false, "whether to enable verbose logging")
2727

2828
var githubToken = os.Getenv("GITHUB_TOKEN")
29+
var githubPath = os.Getenv("GITHUB_PATH")
2930

3031
func main() {
3132
// make sure that the required flags and env vars are set
@@ -36,6 +37,10 @@ func main() {
3637
// this is used by the GH client transparently
3738
log.Fatalf("GITHUB_TOKEN must be set")
3839
}
40+
if githubPath == "" {
41+
// this is used to add the installed binary to the actions path
42+
log.Fatalf("GITHUB_PATH must be set")
43+
}
3944

4045
// check that we can use the supplied pattern to match assets
4146
assetPatternRegexp, err := regexp.Compile(strings.TrimSpace(*assetPattern))
@@ -44,7 +49,7 @@ func main() {
4449
}
4550

4651
// list releases for the repo
47-
log.Printf("Listing releases for %s/%s", *owner, *repo)
52+
log.Printf("listing releases for %s/%s", *owner, *repo)
4853
client := github.NewClient(nil)
4954

5055
var release *github.RepositoryRelease
@@ -93,7 +98,7 @@ func main() {
9398
}
9499

95100
// download the asset to a tempdir
96-
log.Println("downloading matching asset")
101+
log.Printf("downloading matching asset: %s", assetDownloadURL)
97102
resp, err := http.Get(assetDownloadURL)
98103
if err != nil {
99104
log.Fatalf("failed to get release asset: %s", err)
@@ -107,7 +112,7 @@ func main() {
107112

108113
// extract the download if needed
109114
var binaryPath string
110-
if strings.HasSuffix(*assetPattern, "tar.gz") {
115+
if strings.HasSuffix(assetDownloadURL, ".tar.gz") {
111116
log.Println("unpacking tar.gz to temp dir")
112117

113118
err = untar(dir, resp.Body)
@@ -134,6 +139,9 @@ func main() {
134139
}
135140

136141
if http.DetectContentType(byteSlice) == "application/octet-stream" {
142+
if *verbose {
143+
log.Printf("selected binary '%s' from tar", item.Name())
144+
}
137145
binaryItems = append(binaryItems, itemPath)
138146
}
139147
}
@@ -165,6 +173,16 @@ func main() {
165173
if err != nil {
166174
log.Fatalf("failed to set binary as executable: %s", err)
167175
}
176+
177+
// add the new binary to the GITHUB_PATH
178+
f, err := os.OpenFile(githubPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
179+
if err != nil {
180+
log.Fatalf("failed to open GH path: %s", err)
181+
}
182+
defer f.Close()
183+
if _, err := f.WriteString(filepath.Dir(*installPath) + "\n"); err != nil {
184+
log.Fatalf("failed to update GH path: %s", err)
185+
}
168186
}
169187

170188
func validateFlags() {

0 commit comments

Comments
 (0)