145 lines
4.6 KiB
YAML
145 lines
4.6 KiB
YAML
name: Build and Release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- '*'
|
|
|
|
jobs:
|
|
build:
|
|
name: Build
|
|
runs-on: self-hosted
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: '1.21'
|
|
|
|
- name: Check out code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Generate build variables
|
|
id: prep
|
|
run: |
|
|
echo "version=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_OUTPUT
|
|
echo "built_at=$(date +%Y-%m-%dT%H:%M:%S)" >> $GITHUB_OUTPUT
|
|
echo "git_commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Cross-compile with xgo
|
|
uses: crazy-max/ghaction-xgo@v3
|
|
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
|
|
with:
|
|
xgo_version: latest
|
|
go_version: 1.21
|
|
pkg: cmd/zurg
|
|
targets: linux/amd64
|
|
dest: artifacts
|
|
prefix: zurg
|
|
v: false
|
|
x: false
|
|
race: false
|
|
ldflags: >
|
|
-s -w
|
|
-X 'github.com/debridmediamanager/zurg/internal/version.BuiltAt=${{ steps.prep.outputs.built_at }}'
|
|
-X 'github.com/debridmediamanager/zurg/internal/version.GitCommit=${{ steps.prep.outputs.git_commit }}'
|
|
-X 'github.com/debridmediamanager/zurg/internal/version.Version=${{ steps.prep.outputs.version }}'
|
|
buildmode: default
|
|
trimpath: true
|
|
|
|
- name: Cross-compile with xgo
|
|
uses: crazy-max/ghaction-xgo@v3
|
|
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
|
|
with:
|
|
xgo_version: latest
|
|
go_version: 1.21
|
|
pkg: cmd/zurg
|
|
dest: artifacts
|
|
prefix: zurg
|
|
v: false
|
|
x: false
|
|
race: false
|
|
ldflags: >
|
|
-s -w
|
|
-X 'github.com/debridmediamanager/zurg/internal/version.BuiltAt=${{ steps.prep.outputs.built_at }}'
|
|
-X 'github.com/debridmediamanager/zurg/internal/version.GitCommit=${{ steps.prep.outputs.git_commit }}'
|
|
-X 'github.com/debridmediamanager/zurg/internal/version.Version=${{ steps.prep.outputs.version }}'
|
|
buildmode: default
|
|
trimpath: true
|
|
|
|
- name: Compress artifacts
|
|
run: |
|
|
mkdir -p compressed_artifacts
|
|
for file in artifacts/*; do
|
|
# Extract platform from the filename
|
|
platform=$(basename $file | sed 's/zurg-//; s/.exe//')
|
|
|
|
# Determine if it's a Windows executable
|
|
extension=""
|
|
if [[ $file == *".exe" ]]; then
|
|
extension=".exe"
|
|
fi
|
|
|
|
# Copy and zip the file
|
|
cp -fR "$file" "artifacts/zurg$extension"
|
|
(cd artifacts && zip -r "../compressed_artifacts/zurg-${{ steps.prep.outputs.version }}-$platform.zip" "zurg$extension")
|
|
done
|
|
|
|
- name: Upload artifacts to workflow
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: compiled-binaries
|
|
path: compressed_artifacts/
|
|
|
|
release:
|
|
name: Release
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- name: Set version
|
|
id: version
|
|
run: echo "::set-output name=version::$(echo ${GITHUB_REF#refs/tags/})"
|
|
|
|
- name: Download artifacts
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: compiled-binaries
|
|
path: compressed_artifacts
|
|
|
|
- name: Publish to zurg-testing
|
|
run: |
|
|
git config --global user.name "Zurg"
|
|
git config --global user.email "zurg@debridmediamanager.com"
|
|
git lfs install
|
|
|
|
- name: Publish to zurg-early-releases
|
|
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
|
|
run: |
|
|
git clone https://x-access-token:${{ secrets.TOKEN }}@github.com/debridmediamanager/zurg-early-releases.git
|
|
mkdir -p zurg-early-releases/releases/${{ steps.version.outputs.version }}
|
|
cp -fR compressed_artifacts/* zurg-early-releases/releases/${{ steps.version.outputs.version }}
|
|
cd zurg-early-releases/releases/${{ steps.version.outputs.version }}
|
|
git lfs track "*.zip"
|
|
git add .
|
|
git commit -m "Release ${{ steps.version.outputs.version }}"
|
|
git push
|
|
|
|
|
|
- name: Publish to zurg-testing
|
|
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
|
|
run: |
|
|
git clone https://x-access-token:${{ secrets.TOKEN }}@github.com/debridmediamanager/zurg-testing.git
|
|
mkdir -p zurg-testing/releases/${{ steps.version.outputs.version }}
|
|
cp -fR compressed_artifacts/* zurg-testing/releases/${{ steps.version.outputs.version }}
|
|
cd zurg-testing/releases/${{ steps.version.outputs.version }}
|
|
git lfs track "*.zip"
|
|
git add .
|
|
git commit -m "Release ${{ steps.version.outputs.version }}"
|
|
git push
|