Skip to content

Commit 5500de2

Browse files
authored
chore: update release actions Close #58
1 parent 204e20a commit 5500de2

1 file changed

Lines changed: 131 additions & 137 deletions

File tree

.github/workflows/release.yml

Lines changed: 131 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -4,141 +4,135 @@ on:
44
types: [created]
55

66
jobs:
7-
build:
8-
name: Build Binary
9-
runs-on: ${{ matrix.os }}
10-
strategy:
11-
matrix:
12-
os: [windows-latest, macos-latest, ubuntu-latest]
13-
arch: [amd64, '386']
14-
include:
15-
- os: windows-latest
16-
goos: windows
17-
bin: 'hack-browser-data.exe'
18-
args: -9
19-
releaseos: windows
20-
- os: macos-latest
21-
goos: darwin
22-
bin: 'hack-browser-data'
23-
args: -9
24-
releaseos: osx
25-
- os: ubuntu-latest
26-
goos: linux
27-
bin: 'hack-browser-data'
28-
args: -9
29-
releaseos: linux
30-
exclude:
31-
- os: macos-latest
32-
arch: '386'
33-
- os: windows-latest
34-
arch: '386'
35-
steps:
36-
- name: Set up Go
37-
uses: actions/setup-go@v2
38-
with:
39-
go-version: 1.15
40-
- if: matrix.os == 'ubuntu-latest'
41-
run: sudo apt-get update && sudo apt-get install -y gcc-multilib
42-
- if: matrix.arch == '386'
43-
run: echo "RELEASE=hack-browser-data-${{ github.event.release.tag_name}}-${{ matrix.releaseos}}-32bit" >> $GITHUB_ENV
44-
- if: matrix.arch == 'amd64'
45-
run: echo "RELEASE=hack-browser-data-${{ github.event.release.tag_name}}-${{ matrix.releaseos}}-64bit" >> $GITHUB_ENV
46-
- if: matrix.os == 'windows-latest'
47-
shell: powershell
48-
run: echo "RELEASE=hack-browser-data-${{ github.event.release.tag_name}}-${{ matrix.releaseos}}-64bit" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
49-
- uses: actions/checkout@v2
50-
- name: Build ${{ matrix.goos }}/${{ matrix.arch }}
51-
run: go build -ldflags '-w -s' -o ${{ matrix.bin }}
52-
env:
53-
GOOS: ${{ matrix.goos }}
54-
GOARCH: ${{ matrix.arch }}
55-
CGO_ENABLED: 1
56-
- uses: svenstaro/upx-action@v2
57-
with:
58-
args: ${{ matrix.args }}
59-
file: ${{ matrix.bin }}
60-
- name: Upload to artifacts
61-
uses: actions/upload-artifact@v2
62-
with:
63-
name: ${{ env.RELEASE }}
64-
path: ${{ matrix.bin }}
65-
package:
66-
name: Package Assets
67-
runs-on: ubuntu-latest
68-
needs: build
69-
steps:
70-
- uses: actions/checkout@v2
71-
- uses: actions/download-artifact@v2
72-
with:
73-
path: bin
74-
- name: Package Releases
75-
run: |
76-
mkdir releases;
77-
for RELEASE_DIR in bin/*
78-
do
79-
echo "Creating release $RELEASE_DIR"
80-
for BINARY in $RELEASE_DIR/*
81-
do
82-
chmod 777 $BINARY;
83-
cp $BINARY .;
84-
zip -r releases/$(basename $RELEASE_DIR).zip \
85-
$(basename ${BINARY}) \
86-
README.md \
87-
README_ZH.md;
88-
rm $BINARY;
89-
done
90-
done
91-
- name: Upload to artifacts
92-
uses: actions/upload-artifact@v2
93-
with:
94-
name: releases
95-
path: releases/*.zip
7+
build:
8+
runs-on: ubuntu-latest
969

97-
upload:
98-
name: Upload to the Release
99-
runs-on: ubuntu-latest
100-
needs: package
101-
steps:
102-
- uses: actions/download-artifact@v2
103-
with:
104-
name: releases
105-
path: releases/
106-
- name: Upload Archives to Release
107-
env:
108-
UPLOAD_URL: ${{ github.event.release.upload_url }}
109-
API_HEADER: "Accept: application/vnd.github.v3+json"
110-
AUTH_HEADER: "Authorization: token ${{ secrets.GITHUB_TOKEN }}"
111-
run: |
112-
UPLOAD_URL=$(echo -n $UPLOAD_URL | sed s/\{.*//g)
113-
for FILE in releases/*
114-
do
115-
echo "Uploading ${FILE}";
116-
curl \
117-
-H "${API_HEADER}" \
118-
-H "${AUTH_HEADER}" \
119-
-H "Content-Type: $(file -b --mime-type ${FILE})" \
120-
--data-binary "@${FILE}" \
121-
"${UPLOAD_URL}?name=$(basename ${FILE})";
122-
done
123-
- name: Generate SHA256 Hashes
124-
env:
125-
API_HEADER: "Accept: application/vnd.github.v3+json"
126-
AUTH_HEADER: "Authorization: token ${{ secrets.GITHUB_TOKEN }}"
127-
RELEASE_URL: ${{ github.event.release.url }}
128-
run: |
129-
HASH_TABLE="| SHA256 Hash | Filename |"
130-
HASH_TABLE="${HASH_TABLE}\n|-----|-----|\n"
131-
for FILE in releases/*
132-
do
133-
FILENAME=$(basename ${FILE})
134-
HASH=$(sha256sum ${FILE} | cut -d ' ' -f 1)
135-
HASH_TABLE="${HASH_TABLE}|${HASH}|${FILENAME}|\n"
136-
done
137-
echo "${HASH_TABLE}"
138-
curl \
139-
-XPATCH \
140-
-H "${API_HEADER}" \
141-
-H "${AUTH_HEADER}" \
142-
-H "Content-Type: application/json" \
143-
-d "{\"body\": \"${HASH_TABLE}\"}" \
144-
"${RELEASE_URL}";
10+
steps:
11+
- name: Checkout source
12+
uses: actions/checkout@v1
13+
14+
- name: Use Golang
15+
uses: actions/setup-go@v1
16+
with:
17+
go-version: "1.15"
18+
19+
-
20+
name: Build with xgo
21+
uses: crazy-max/ghaction-xgo@v1
22+
with:
23+
xgo_version: latest
24+
go_version: ${{ matrix.go_version }}
25+
dest: build
26+
prefix: hack-browser-data
27+
targets: windows/amd64,windows/386,linux/386,linux/amd64,linux/arm,linux/arm64,darwin/amd64
28+
v: true
29+
x: false
30+
race: false
31+
ldflags: -s -w
32+
buildmode: default
33+
34+
- name: Set Variable
35+
run: |
36+
echo "RELEASE_WIN32=hack-browser-data-${{ github.event.release.tag_name}}windows-32bit" >> $GITHUB_ENV
37+
echo "RELEASE_WIN64=hack-browser-data-${{ github.event.release.tag_name}}windows-64bit" >> $GITHUB_ENV
38+
echo "RELEASE_OSX=hack-browser-data-${{ github.event.release.tag_name}}osx-64bit" >> $GITHUB_ENV
39+
echo "RELEASE_Linux386=hack-browser-data-${{ github.event.release.tag_name}}linux-386" >> $GITHUB_ENV
40+
echo "RELEASE_LinuxARM64=hack-browser-data-${{ github.event.release.tag_name}}linux-arm64" >> $GITHUB_ENV
41+
echo "RELEASE_LinuxAMD64=hack-browser-data-${{ github.event.release.tag_name}}linux-amd64" >> $GITHUB_ENV
42+
echo "RELEASE_LinuxARM=hack-browser-data-${{ github.event.release.tag_name}}linux-arm" >> $GITHUB_ENV
43+
- name: Build zip
44+
run: |
45+
mv build/hack-browser-data-windows*386.exe "$RELEASE_WIN32".exe
46+
mv build/hack-browser-data-windows*amd64.exe "$RELEASE_WIN64".exe
47+
mv build/hack-browser-data-linux-*386 "$RELEASE_Linux386"
48+
mv build/hack-browser-data-linux-*amd64 "$RELEASE_LinuxAMD64"
49+
mv build/hack-browser-data-linux-*arm64 "$RELEASE_LinuxARM64"
50+
mv build/hack-browser-data-linux-*arm-* "$RELEASE_LinuxARM"
51+
mv build/hack-browser-data-darwin-*amd64 "$RELEASE_OSX"
52+
zip "$RELEASE_WIN32".zip "$RELEASE_WIN32".exe
53+
zip "$RELEASE_WIN64".zip "$RELEASE_WIN64".exe
54+
zip "$RELEASE_Linux386".zip "$RELEASE_Linux386"
55+
zip "$RELEASE_LinuxAMD64".zip "$RELEASE_LinuxAMD64"
56+
zip "$RELEASE_LinuxARM64".zip "$RELEASE_Linux386"
57+
zip "$RELEASE_LinuxARM".zip "$RELEASE_LinuxARM"
58+
zip "$RELEASE_OSX".zip "$RELEASE_OSX"
59+
- name: Create Release
60+
id: create_release
61+
uses: monkeyWie/create-release@master
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
with:
65+
tag_name: ${{ github.ref }}
66+
release_name: Release ${{ github.ref }}
67+
draft: false
68+
prerelease: true
69+
70+
- name: Upload Release - Windows 64bit
71+
uses: actions/[email protected]
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
with:
75+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
76+
asset_path: ./${{ env.RELEASE_WIN64 }}.zip
77+
asset_name: ${{ env.RELEASE_WIN64 }}.zip
78+
asset_content_type: application/zip
79+
80+
- name: Upload Release - Windows 32bit
81+
uses: actions/[email protected]
82+
env:
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
with:
85+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
86+
asset_path: ./${{ env.RELEASE_WIN32 }}.zip
87+
asset_name: ${{ env.RELEASE_WIN32 }}.zip
88+
asset_content_type: application/zip
89+
90+
- name: Upload Release - Linux amd64
91+
uses: actions/[email protected]
92+
env:
93+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94+
with:
95+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
96+
asset_path: ./${{ env.RELEASE_LinuxAMD64 }}.zip
97+
asset_name: ${{ env.RELEASE_LinuxAMD64 }}.zip
98+
asset_content_type: application/zip
99+
100+
- name: Upload Release - Linux 386
101+
uses: actions/[email protected]
102+
env:
103+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104+
with:
105+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
106+
asset_path: ./${{ env.RELEASE_Linux386 }}.zip
107+
asset_name: ${{ env.RELEASE_Linux386 }}.zip
108+
asset_content_type: application/zip
109+
110+
- name: Upload Release - Linux arm64
111+
uses: actions/[email protected]
112+
env:
113+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114+
with:
115+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
116+
asset_path: ./${{ env.RELEASE_LinuxARM64 }}.zip
117+
asset_name: ${{ env.RELEASE_LinuxARM64 }}.zip
118+
asset_content_type: application/zip
119+
120+
- name: Upload Release - Linux arm
121+
uses: actions/[email protected]
122+
env:
123+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124+
with:
125+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
126+
asset_path: ./${{ env.RELEASE_LinuxARM }}.zip
127+
asset_name: ${{ env.RELEASE_LinuxARM }}.zip
128+
asset_content_type: application/zip
129+
130+
- name: Upload Release - Darwin amd64
131+
uses: actions/[email protected]
132+
env:
133+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134+
with:
135+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
136+
asset_path: ./${{ env.RELEASE_OSX }}.zip
137+
asset_name: ${{ env.RELEASE_OSX }}.zip
138+
asset_content_type: application/zip

0 commit comments

Comments
 (0)