Github modifications

This commit is contained in:
Salastil
2025-11-23 03:38:46 -05:00
parent 8ededb2f4a
commit 9865fd675a

View File

@@ -1,8 +1,6 @@
name: Build release binaries name: Build release binaries
on: on:
release:
types: [published]
push: push:
tags: tags:
- "v*" - "v*"
@@ -16,30 +14,19 @@ env:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
include: include:
- goos: linux - goos: linux
goarch: amd64 goarch: amd64
archive: tar.gz
extension: ""
- goos: linux - goos: linux
goarch: arm64 goarch: arm64
archive: tar.gz
extension: ""
- goos: windows
goarch: amd64
archive: zip
extension: ".exe"
- goos: darwin - goos: darwin
goarch: amd64 goarch: amd64
archive: tar.gz
extension: ""
- goos: darwin - goos: darwin
goarch: arm64 goarch: arm64
archive: tar.gz
extension: ""
steps: steps:
- name: Checkout repository - name: Checkout repository
@@ -51,42 +38,55 @@ jobs:
go-version-file: go.mod go-version-file: go.mod
cache: true cache: true
- name: Build ${{ matrix.goos }} ${{ matrix.goarch }} binary - name: Build ${{ matrix.goos }} ${{ matrix.goarch }}
env: env:
GOOS: ${{ matrix.goos }} GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }} GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0 CGO_ENABLED: 0
EXTENSION: ${{ matrix.extension }}
run: | run: |
mkdir -p dist mkdir -p dist/bin
OUTPUT="${BINARY_NAME}${EXTENSION}" go build -o "dist/bin/${BINARY_NAME}" .
go build -o "dist/${OUTPUT}" .
- name: Package artifact - name: Package binary only
env:
EXTENSION: ${{ matrix.extension }}
run: | run: |
cd dist cd dist/bin
OUTPUT="${BINARY_NAME}${EXTENSION}" tar -czf "../${BINARY_NAME}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz" "${BINARY_NAME}"
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 - name: Upload binary artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: ${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }} name: ${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}
path: dist/${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}.* path: dist/${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz
if-no-files-found: error
source:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create source tarball
run: |
mkdir -p dist
tag="${GITHUB_REF_NAME}"
tar -czf "dist/${{ env.BINARY_NAME }}_${tag}_source.tar.gz" .
- name: Upload source artifact
uses: actions/upload-artifact@v4
with:
name: source_tarball
path: dist/*source.tar.gz
publish: publish:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: build needs: [build, source]
permissions: permissions:
contents: write contents: write
steps: steps:
- name: Download artifacts - name: Download artifacts
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
@@ -94,55 +94,8 @@ jobs:
path: dist path: dist
merge-multiple: true merge-multiple: true
- name: Publish release assets on GitHub - name: Publish assets to GitHub Release
if: startsWith(github.server_url, 'https://github.com')
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
with: with:
tag_name: ${{ github.ref_name }} tag_name: ${{ github.ref_name }}
files: dist/* 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