Skip to content

Build Go binaries and upload release #16

Build Go binaries and upload release

Build Go binaries and upload release #16

Workflow file for this run

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: Upload binaries as artifacts
uses: actions/upload-artifact@v3
with:
name: binaries
path: |
build/darwin-amd64/weave
build/darwin-arm64/weave
build/linux-amd64/weave
build/linux-arm64/weave
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.WEAVE_BINARIES_GITHUB_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 weave; do
binary_path=$(find build -name $file)
if [ -f $binary_path ]; then
curl -X POST \
-H "Authorization: token ${{ secrets.WEAVE_BINARIES_GITHUB_TOKEN }}" \
-H "Content-Type: application/octet-stream" \
--data-binary @$binary_path \
"https://uploads.github.com/repos/initia-labs/weave-binaries/releases/$RELEASE_ID/assets?name=$(basename $binary_path)"
else
echo "Warning: Binary file $file not found in build directory."
fi
done
env:
WEAVE_BINARIES_GITHUB_TOKEN: ${{ secrets.WEAVE_BINARIES_GITHUB_TOKEN }}