Github modifications
This commit is contained in:
117
.github/workflows/release.yml
vendored
117
.github/workflows/release.yml
vendored
@@ -1,8 +1,6 @@
|
||||
name: Build release binaries
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
@@ -16,30 +14,19 @@ env:
|
||||
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
|
||||
@@ -51,42 +38,55 @@ jobs:
|
||||
go-version-file: go.mod
|
||||
cache: true
|
||||
|
||||
- name: Build ${{ matrix.goos }} ${{ matrix.goarch }} binary
|
||||
- name: Build ${{ matrix.goos }} ${{ matrix.goarch }}
|
||||
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}" .
|
||||
mkdir -p dist/bin
|
||||
go build -o "dist/bin/${BINARY_NAME}" .
|
||||
|
||||
- name: Package artifact
|
||||
env:
|
||||
EXTENSION: ${{ matrix.extension }}
|
||||
- name: Package binary only
|
||||
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
|
||||
cd dist/bin
|
||||
tar -czf "../${BINARY_NAME}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz" "${BINARY_NAME}"
|
||||
|
||||
- name: Upload build artifact
|
||||
- name: Upload binary 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
|
||||
path: dist/${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz
|
||||
|
||||
|
||||
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:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
needs: [build, source]
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
@@ -94,55 +94,8 @@ jobs:
|
||||
path: dist
|
||||
merge-multiple: true
|
||||
|
||||
- name: Publish release assets on GitHub
|
||||
if: startsWith(github.server_url, 'https://github.com')
|
||||
- name: Publish assets to GitHub Release
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user