This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
name: Build release binaries
|
name: Build Release Binaries
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
@@ -12,34 +12,11 @@ permissions:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
BINARY_NAME: streamed-tui
|
BINARY_NAME: streamed-tui
|
||||||
|
API_BASE: https://git.salastil.com/api/v1
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build-and-release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- goos: linux
|
|
||||||
goarch: amd64
|
|
||||||
archive: tar.gz
|
|
||||||
extension: ""
|
|
||||||
- goos: linux
|
|
||||||
goarch: arm64
|
|
||||||
archive: tar.gz
|
|
||||||
extension: ""
|
|
||||||
- goos: windows
|
|
||||||
goarch: amd64
|
|
||||||
archive: zip
|
|
||||||
extension: ".exe"
|
|
||||||
- goos: darwin
|
|
||||||
goarch: amd64
|
|
||||||
archive: tar.gz
|
|
||||||
extension: ""
|
|
||||||
- goos: darwin
|
|
||||||
goarch: arm64
|
|
||||||
archive: tar.gz
|
|
||||||
extension: ""
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
@@ -51,71 +28,100 @@ jobs:
|
|||||||
go-version-file: go.mod
|
go-version-file: go.mod
|
||||||
cache: true
|
cache: true
|
||||||
|
|
||||||
- name: Build ${{ matrix.goos }} ${{ matrix.goarch }} binary
|
- name: Build all platform binaries
|
||||||
env:
|
|
||||||
GOOS: ${{ matrix.goos }}
|
|
||||||
GOARCH: ${{ matrix.goarch }}
|
|
||||||
CGO_ENABLED: 0
|
|
||||||
EXTENSION: ${{ matrix.extension }}
|
|
||||||
run: |
|
run: |
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
OUTPUT="${BINARY_NAME}${EXTENSION}"
|
|
||||||
go build -o "dist/${OUTPUT}" .
|
|
||||||
|
|
||||||
- name: Package artifact
|
build() {
|
||||||
env:
|
GOOS=$1 GOARCH=$2 EXT=$3
|
||||||
EXTENSION: ${{ matrix.extension }}
|
OUT="${BINARY_NAME}${EXT}"
|
||||||
|
echo "Building $1 $2 => $OUT"
|
||||||
|
env GOOS=$1 GOARCH=$2 CGO_ENABLED=0 go build -o "dist/${OUT}" .
|
||||||
|
}
|
||||||
|
|
||||||
|
build linux amd64 ""
|
||||||
|
build linux arm64 ""
|
||||||
|
build windows amd64 ".exe"
|
||||||
|
build darwin amd64 ""
|
||||||
|
build darwin arm64 ""
|
||||||
|
|
||||||
|
- name: Package binaries
|
||||||
run: |
|
run: |
|
||||||
cd dist
|
cd dist
|
||||||
OUTPUT="${BINARY_NAME}${EXTENSION}"
|
|
||||||
ARCHIVE="${BINARY_NAME}_${{ matrix.goos }}_${{ matrix.goarch }}"
|
pack() {
|
||||||
if [ "${{ matrix.archive }}" = "zip" ]; then
|
NAME="$1"
|
||||||
zip "${ARCHIVE}.zip" "${OUTPUT}"
|
EXT="$2"
|
||||||
|
|
||||||
|
if [[ "$EXT" == "zip" ]]; then
|
||||||
|
zip "${NAME}.zip" "${BINARY_NAME}${3}"
|
||||||
else
|
else
|
||||||
tar -czf "${ARCHIVE}.tar.gz" "${OUTPUT}"
|
tar -czf "${NAME}.tar.gz" "${BINARY_NAME}${3}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
pack streamed-tui_linux_amd64 tar.gz ""
|
||||||
|
pack streamed-tui_linux_arm64 tar.gz ""
|
||||||
|
pack streamed-tui_windows_amd64 zip ".exe"
|
||||||
|
pack streamed-tui_darwin_amd64 tar.gz ""
|
||||||
|
pack streamed-tui_darwin_arm64 tar.gz ""
|
||||||
|
|
||||||
|
- name: Create release in Gitea
|
||||||
|
id: create_release
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.CI_TOKEN }}
|
||||||
|
TAG: ${{ github.ref_name }}
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
API_BASE: ${{ env.API_BASE }}
|
||||||
|
run: |
|
||||||
|
if [ -z "$GITEA_TOKEN" ]; then
|
||||||
|
echo "ERROR: Missing CI_TOKEN secret"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Upload build artifact
|
echo "Creating release for tag: $TAG"
|
||||||
uses: https://gitea.com/actions/upload-artifact@v1
|
|
||||||
with:
|
|
||||||
name: ${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}
|
|
||||||
path: dist/${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}.*
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
publish:
|
RESPONSE=$(curl -s -X POST \
|
||||||
runs-on: ubuntu-latest
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
needs: build
|
-H "Content-Type: application/json" \
|
||||||
permissions:
|
-d "{
|
||||||
contents: write
|
\"tag_name\": \"${TAG}\",
|
||||||
steps:
|
\"name\": \"Release ${TAG}\",
|
||||||
- name: Download artifacts
|
\"body\": \"Automated release for ${TAG}\",
|
||||||
uses: https://gitea.com/actions/download-artifact@v1
|
\"draft\": false,
|
||||||
with:
|
\"prerelease\": false
|
||||||
path: dist
|
}" \
|
||||||
merge-multiple: true
|
"${API_BASE}/repos/${REPO}/releases")
|
||||||
|
|
||||||
- name: Publish release assets on GitHub
|
echo "RESPONSE=$RESPONSE"
|
||||||
if: startsWith(github.server_url, 'https://github.com')
|
|
||||||
uses: softprops/action-gh-release@v2
|
|
||||||
with:
|
|
||||||
files: dist/*
|
|
||||||
|
|
||||||
- name: Publish release assets on Gitea
|
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*')
|
||||||
if: startsWith(github.server_url, 'https://github.com') == false
|
echo "Release ID: $RELEASE_ID"
|
||||||
|
|
||||||
|
if [ -z "$RELEASE_ID" ]; then
|
||||||
|
echo "ERROR: Failed to extract release ID"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "release_id=${RELEASE_ID}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Upload release assets
|
||||||
env:
|
env:
|
||||||
API_URL: ${{ github.api_url }}
|
GITEA_TOKEN: ${{ secrets.CI_TOKEN }}
|
||||||
REPOSITORY: ${{ github.repository }}
|
RELEASE_ID: ${{ steps.create_release.outputs.release_id }}
|
||||||
RELEASE_ID: ${{ github.event.release.id }}
|
API_BASE: ${{ env.API_BASE }}
|
||||||
TOKEN: ${{ secrets.CI_TOKEN || secrets.GITHUB_TOKEN || github.token }}
|
REPO: ${{ github.repository }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
echo "Uploading assets..."
|
||||||
shopt -s nullglob
|
cd dist
|
||||||
for file in dist/*; do
|
|
||||||
name=$(basename "${file}")
|
for file in *; do
|
||||||
curl -sfSL -X POST \
|
echo "Uploading $file..."
|
||||||
-H "Authorization: token ${TOKEN}" \
|
curl -s -X POST \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
-H "Content-Type: application/octet-stream" \
|
-H "Content-Type: application/octet-stream" \
|
||||||
--data-binary @"${file}" \
|
--data-binary @"$file" \
|
||||||
"${API_URL}/repos/${REPOSITORY}/releases/${RELEASE_ID}/assets?name=${name}"
|
"${API_BASE}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=$file"
|
||||||
done
|
done
|
||||||
shell: bash
|
|
||||||
|
echo "All assets uploaded."
|
||||||
|
|||||||
Reference in New Issue
Block a user