Files
zurg/.github/workflows/binary-build.yml
2023-10-28 23:36:12 +02:00

124 lines
3.9 KiB
YAML

name: Build zurg-testing executable binary
on:
push:
branches:
- main
tags:
- v0*
- latest
jobs:
determine_version:
runs-on: ubuntu-latest
outputs:
build_version: ${{ steps.set_version.outputs.version }}
steps:
- id: set_version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
else
echo "version=latest" >> $GITHUB_OUTPUT
fi
build:
name: Build
runs-on: ubuntu-latest
needs: determine_version
strategy:
matrix:
goos: [windows, darwin, linux]
goarch: [386, amd64, arm, arm64]
exclude:
- goos: darwin
goarch: 386
- goos: darwin
goarch: arm
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 'stable'
- name: Build
run: |
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o zurg-${{ needs.determine_version.outputs.build_version }}-${{ matrix.goos }}-${{ matrix.goarch }} cmd/zurg/main.go
# Install and use UPX to compress the binary, but exclude specific combinations
- name: Install and Compress with UPX
if: (matrix.goos != 'windows' || matrix.goarch != 'arm') && (matrix.goos != 'windows' || matrix.goarch != 'arm64')
run: |
sudo apt-get update
sudo apt-get install -y upx-ucl
upx --best zurg-${{ needs.determine_version.outputs.build_version }}-${{ matrix.goos }}-${{ matrix.goarch }}
# Zip the binary
- name: Zip Binary
run: |
zip zurg-${{ needs.determine_version.outputs.build_version }}-${{ matrix.goos }}-${{ matrix.goarch }}.zip zurg-${{ needs.determine_version.outputs.build_version }}-${{ matrix.goos }}-${{ matrix.goarch }}
# List files (for debugging)
- name: List files
run: ls -alh
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: zurg-${{ needs.determine_version.outputs.build_version }}-${{ matrix.goos }}-${{ matrix.goarch }}.zip
path: zurg-${{ needs.determine_version.outputs.build_version }}-${{ matrix.goos }}-${{ matrix.goarch }}.zip
release:
needs:
- determine_version
- build
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v3
- name: Install jq
run: sudo apt-get install jq
- name: Create Release in other repo
id: create_release
run: |
# Generate the current date in the required format
CURRENT_DATE=$(date +'%Y%m%d%H%M')
# Create the release in the other repo
RESPONSE=$(curl -s -X POST \
-H "Authorization: token ${{ secrets.PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/debridmediamanager/zurg-testing/releases \
-d '{
"tag_name": "release-'$CURRENT_DATE'",
"name": "Release '$CURRENT_DATE'",
"draft": false,
"prerelease": false
}')
# Extract the release ID from the response
RELEASE_ID=$(echo "$RESPONSE" | jq ".id")
# Set the RELEASE_ID environment variable for subsequent steps
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV
- name: Upload Artifacts to other repo's release
run: |
for artifact in $(ls); do
if [[ -f "$artifact" ]]; then
curl -s -X POST \
-H "Authorization: token ${{ secrets.PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Content-Type: $(file -b --mime-type $artifact)" \
--data-binary "@$artifact" \
"https://uploads.github.com/repos/debridmediamanager/zurg-testing/releases/${RELEASE_ID}/assets?name=$(basename $artifact)"
fi
done