Last active
March 5, 2022 10:55
-
-
Save brownhash/5944b2eb33ec75c554c74f1950702f83 to your computer and use it in GitHub Desktop.
Github workflow file for releasing artifacts of a golang tool
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
name: tool-release | |
on: | |
pull_request: | |
types: [closed] | |
jobs: | |
release: | |
name: tool-release | |
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'master' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- id: changed_files | |
uses: jitterbit/get-changed-files@v1 | |
- name: Check commit version | |
id: commit | |
run: | | |
echo "::set-output name=version::$(add command to get tool version)" | |
- name: Create Tag | |
uses: negz/create-tag@v1 | |
with: | |
version: ${{ steps.commit.outputs.version }} | |
message: ${{ steps.commit.outputs.version }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/setup-go@v2 | |
with: | |
go-version: 'go version' | |
- name: Create Release Asset | |
run: | | |
go mod download | |
mkdir -p bin/tool_darwin_amd64 | |
env GOOS=darwin GOARCH=amd64 go build -o bin/tool_darwin_amd64/tool | |
mkdir -p bin/tool_darwin_arm64 | |
env GOOS=darwin GOARCH=arm64 go build -o bin/tool_darwin_arm64/tool | |
mkdir -p bin/tool_linux_amd64 | |
env GOOS=linux GOARCH=amd64 go build -o bin/tool_linux_amd64/tool | |
cd bin/tool_darwin_amd64 && tar -czvf ../tool_darwin_amd64.tar.gz tool | |
cd bin/tool_darwin_arm64 && tar -czvf ../tool_darwin_arm64.tar.gz tool | |
cd bin/tool_linux_amd64 && tar -czvf ../tool_linux_amd64.tar.gz tool | |
- name: Generate Asset SHA256 | |
id: sha256 | |
run: | | |
echo "::set-output name=darwin_amd64::$(shasum -a 256 bin/tool_darwin_amd64.tar.gz | cut -d' ' -f1)" | |
echo "::set-output name=darwin_arm64::$(shasum -a 256 bin/tool_darwin_arm64.tar.gz | cut -d' ' -f1)" | |
echo "::set-output name=linux_amd64::$(shasum -a 256 bin/tool_linux_amd64.tar.gz | cut -d' ' -f1)" | |
- name: Create Release | |
uses: ncipollo/release-action@v1 | |
with: | |
name: Release ${{ steps.commit.outputs.version }} | |
tag: ${{ steps.commit.outputs.version }} | |
artifacts: "bin/*.tar.gz" | |
body: | | |
--- | |
### Assets | |
#### Darwin AMD64 | |
- Asset Url: https://github.com/owner/tool/releases/download/${{ steps.commit.outputs.version }}/tool_darwin_amd64.tar.gz | |
- SHA Checksum: `${{ steps.sha256.outputs.darwin_amd64 }}` | |
#### Darwin ARM64 | |
- Asset Url: https://github.com/owner/tool/releases/download/${{ steps.commit.outputs.version }}/tool_darwin_arm64.tar.gz | |
- SHA Checksum: `${{ steps.sha256.outputs.darwin_arm64 }}` | |
#### Linux AMD64 | |
- Asset Url: https://github.com/owner/tool/releases/download/${{ steps.commit.outputs.version }}/tool_linux_amd64.tar.gz | |
- SHA Checksum: `${{ steps.sha256.outputs.linux_amd64 }}` | |
token: ${{ secrets.GITHUB_TOKEN }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment