Build Go binaries and upload release #12
Workflow file for this run
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: Build Go binaries and upload to weave-binaries release | |
on: | |
release: | |
types: | |
- published | |
jobs: | |
build: | |
name: Build Go binaries | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
goos: [linux, darwin] | |
goarch: [amd64, arm64] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.22.6' | |
- name: Build binary | |
run: | | |
mkdir -p build/${{ matrix.goos }}-${{ matrix.goarch }} | |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o build/${{ matrix.goos }}-${{ matrix.goarch }}/weave | |
- name: List files in build directory (optional for debugging) | |
run: ls -R build/ | |
- name: Create zip files for binaries | |
run: | | |
zip -j darwin-amd64-binary.zip build/darwin-amd64/weave | |
zip -j darwin-arm64-binary.zip build/darwin-arm64/weave | |
zip -j linux-amd64-binary.zip build/linux-amd64/weave | |
zip -j linux-arm64-binary.zip build/linux-arm64/weave | |
- name: Upload binaries as artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: binaries | |
path: | | |
darwin-amd64-binary.zip | |
darwin-arm64-binary.zip | |
linux-amd64-binary.zip | |
linux-arm64-binary.zip | |
upload-to-weave-binaries: | |
name: Upload to weave-binaries release | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download binaries | |
uses: actions/download-artifact@v3 | |
with: | |
name: binaries | |
- name: Create a release in weave-binaries | |
run: | | |
RELEASE_ID=$(curl -s -X POST \ | |
-H "Authorization: token ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/initia-labs/weave-binaries/releases \ | |
-d '{ | |
"tag_name": "${{ github.event.release.tag_name }}", | |
"target_commitish": "main", | |
"name": "${{ github.event.release.name }}", | |
"body": "Release for ${{ github.event.release.tag_name }}", | |
"draft": false, | |
"prerelease": false | |
}' | jq -r '.id') | |
for file in darwin-amd64-binary.zip darwin-arm64-binary.zip linux-amd64-binary.zip linux-arm64-binary.zip; do | |
curl -X POST \ | |
-H "Authorization: token ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ | |
-H "Content-Type: application/zip" \ | |
--data-binary @$file \ | |
"https://uploads.github.com/repos/initia-labs/weave-binaries/releases/$RELEASE_ID/assets?name=$(basename $file)" | |
done | |
env: | |
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |