Compare commits

...

5 Commits

Author SHA1 Message Date
Salastil
8665809b24 Merge pull request #3 from Salastil/codex/add-build-scripts-for-versioned-tags
Build releases on tagged pushes
2025-11-23 02:44:19 -05:00
Salastil
2ea57d6973 Build releases on tagged pushes 2025-11-23 02:43:57 -05:00
Salastil
da782d7707 Merge branch 'main' of git.salastil.com:Salastil/streamed-tui 2025-11-23 02:37:17 -05:00
Salastil
8ce344033f Build configs edit 2025-11-23 02:33:40 -05:00
Salastil
972ffc078a Build configs 2025-11-23 02:33:31 -05:00
2 changed files with 266 additions and 0 deletions

View File

@@ -0,0 +1,118 @@
name: Build release binaries
on:
release:
types: [published]
permissions:
contents: write
env:
BINARY_NAME: streamed-tui
jobs:
build:
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:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Build ${{ matrix.goos }} ${{ matrix.goarch }} binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
EXTENSION: ${{ matrix.extension }}
run: |
mkdir -p dist
OUTPUT="${BINARY_NAME}${EXTENSION}"
go build -o "dist/${OUTPUT}" .
- name: Package artifact
env:
EXTENSION: ${{ matrix.extension }}
run: |
cd dist
OUTPUT="${BINARY_NAME}${EXTENSION}"
ARCHIVE="${BINARY_NAME}_${{ matrix.goos }}_${{ matrix.goarch }}"
if [ "${{ matrix.archive }}" = "zip" ]; then
zip "${ARCHIVE}.zip" "${OUTPUT}"
else
tar -czf "${ARCHIVE}.tar.gz" "${OUTPUT}"
fi
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}
path: dist/${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}.*
if-no-files-found: error
publish:
runs-on: ubuntu-latest
needs: build
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Publish release assets on GitHub
if: startsWith(github.server_url, 'https://github.com')
uses: softprops/action-gh-release@v2
with:
files: dist/*
- name: Publish release assets on Gitea
if: startsWith(github.server_url, 'https://github.com') == false
env:
API_URL: ${{ github.api_url }}
REPOSITORY: ${{ github.repository }}
RELEASE_ID: ${{ github.event.release.id }}
TOKEN: ${{ secrets.CI_TOKEN || secrets.GITHUB_TOKEN || github.token }}
run: |
set -euo pipefail
shopt -s nullglob
for file in dist/*; do
name=$(basename "${file}")
curl -sfSL -X POST \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/octet-stream" \
--data-binary @"${file}" \
"${API_URL}/repos/${REPOSITORY}/releases/${RELEASE_ID}/assets?name=${name}"
done
shell: bash

148
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,148 @@
name: Build release binaries
on:
release:
types: [published]
push:
tags:
- "v*"
permissions:
contents: write
env:
BINARY_NAME: streamed-tui
jobs:
build:
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:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Build ${{ matrix.goos }} ${{ matrix.goarch }} binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
EXTENSION: ${{ matrix.extension }}
run: |
mkdir -p dist
OUTPUT="${BINARY_NAME}${EXTENSION}"
go build -o "dist/${OUTPUT}" .
- name: Package artifact
env:
EXTENSION: ${{ matrix.extension }}
run: |
cd dist
OUTPUT="${BINARY_NAME}${EXTENSION}"
ARCHIVE="${BINARY_NAME}_${{ matrix.goos }}_${{ matrix.goarch }}"
if [ "${{ matrix.archive }}" = "zip" ]; then
zip "${ARCHIVE}.zip" "${OUTPUT}"
else
tar -czf "${ARCHIVE}.tar.gz" "${OUTPUT}"
fi
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}
path: dist/${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}.*
if-no-files-found: error
publish:
runs-on: ubuntu-latest
needs: build
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Publish release assets on GitHub
if: startsWith(github.server_url, 'https://github.com')
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
files: dist/*
- name: Publish release assets on Gitea
if: startsWith(github.server_url, 'https://github.com') == false
env:
API_URL: ${{ github.api_url }}
REPOSITORY: ${{ github.repository }}
TOKEN: ${{ secrets.CI_TOKEN || secrets.GITHUB_TOKEN || github.token }}
RELEASE_ID: ${{ github.event.release.id }}
TAG_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
shopt -s nullglob
if [ -z "${RELEASE_ID:-}" ]; then
echo "Creating release ${TAG_NAME} on Gitea"
response=$(curl -sfSL -X POST \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"${TAG_NAME}\",\"name\":\"${TAG_NAME}\",\"draft\":false,\"prerelease\":false}" \
"${API_URL}/repos/${REPOSITORY}/releases")
RELEASE_ID=$(python - "$response" <<'PY'
import json, sys
try:
data = json.loads(sys.argv[1])
print(data.get("id", ""))
except Exception:
sys.exit(1)
PY
)
if [ -z "${RELEASE_ID}" ]; then
echo "Failed to create release" >&2
exit 1
fi
fi
for file in dist/*; do
name=$(basename "${file}")
curl -sfSL -X POST \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/octet-stream" \
--data-binary @"${file}" \
"${API_URL}/repos/${REPOSITORY}/releases/${RELEASE_ID}/assets?name=${name}"
done
shell: bash