ci(gitea): add validation and release workflows
This commit is contained in:
27
.gitea/workflows/pr-merge-validation.yml
Normal file
27
.gitea/workflows/pr-merge-validation.yml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
name: Pull Request Merge Validation
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types:
|
||||||
|
- closed
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
validate-merged-pr:
|
||||||
|
if: ${{ github.event.pull_request.merged == true }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout merged commit
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ github.event.pull_request.merge_commit_sha }}
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
|
||||||
|
- name: Run full unit test suite
|
||||||
|
run: go test ./...
|
||||||
|
|
||||||
|
- name: Run behavior suite
|
||||||
|
run: ./script/run-behavior-suite-docker.sh
|
||||||
26
.gitea/workflows/pr-validation.yml
Normal file
26
.gitea/workflows/pr-validation.yml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
name: Pull Request Validation
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- synchronize
|
||||||
|
- reopened
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
validate:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
|
||||||
|
- name: Run full unit test suite
|
||||||
|
run: go test ./...
|
||||||
|
|
||||||
|
- name: Run behavior suite
|
||||||
|
run: ./script/run-behavior-suite-docker.sh
|
||||||
23
.gitea/workflows/push-unit-tests.yml
Normal file
23
.gitea/workflows/push-unit-tests.yml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
name: Push Unit Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "**"
|
||||||
|
tags-ignore:
|
||||||
|
- "*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
unit-tests:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
|
||||||
|
- name: Run full unit test suite
|
||||||
|
run: go test ./...
|
||||||
107
.gitea/workflows/tag-build-artifacts.yml
Normal file
107
.gitea/workflows/tag-build-artifacts.yml
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
name: Tag Build Artifacts
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
- goos: linux
|
||||||
|
goarch: arm64
|
||||||
|
- goos: darwin
|
||||||
|
goarch: amd64
|
||||||
|
- goos: darwin
|
||||||
|
goarch: arm64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
|
||||||
|
- name: Build binary
|
||||||
|
run: |
|
||||||
|
mkdir -p dist
|
||||||
|
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CGO_ENABLED=0 \
|
||||||
|
go build -o dist/gosick_${{ matrix.goos }}_${{ matrix.goarch }} ./cmd/homesick
|
||||||
|
|
||||||
|
- name: Package artifact
|
||||||
|
run: |
|
||||||
|
cd dist
|
||||||
|
tar -czf gosick_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz gosick_${{ matrix.goos }}_${{ matrix.goarch }}
|
||||||
|
|
||||||
|
- name: Publish workflow artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: gosick_${{ matrix.goos }}_${{ matrix.goarch }}
|
||||||
|
path: dist/gosick_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz
|
||||||
|
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
env:
|
||||||
|
RELEASE_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
steps:
|
||||||
|
- name: Download build artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: dist
|
||||||
|
|
||||||
|
- name: Ensure jq is installed
|
||||||
|
run: |
|
||||||
|
if ! command -v jq >/dev/null 2>&1; then
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y jq
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Create release if needed and upload assets
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
if [[ -z "${RELEASE_TOKEN:-}" ]]; then
|
||||||
|
echo "RELEASE_TOKEN is empty. Expected secrets.GITHUB_TOKEN to be available." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
tag="${GITHUB_REF_NAME}"
|
||||||
|
api_base="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||||
|
|
||||||
|
release_json="$(curl -sS -H "Authorization: token ${RELEASE_TOKEN}" "${api_base}/releases/tags/${tag}" || true)"
|
||||||
|
release_id="$(printf '%s' "${release_json}" | jq -r '.id // empty')"
|
||||||
|
|
||||||
|
if [[ -z "${release_id}" ]]; then
|
||||||
|
create_payload="$(jq -n --arg tag "${tag}" --arg name "${tag}" '{tag_name:$tag, name:$name, draft:false, prerelease:false}')"
|
||||||
|
release_json="$(curl -sS -X POST \
|
||||||
|
-H "Authorization: token ${RELEASE_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "${create_payload}" \
|
||||||
|
"${api_base}/releases")"
|
||||||
|
release_id="$(printf '%s' "${release_json}" | jq -r '.id // empty')"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${release_id}" ]]; then
|
||||||
|
echo "Unable to determine or create release id for tag ${tag}" >&2
|
||||||
|
printf '%s\n' "${release_json}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
find dist -type f -name '*.tar.gz' -print0 | while IFS= read -r -d '' file; do
|
||||||
|
asset_name="$(basename "${file}")"
|
||||||
|
curl -sS -X POST \
|
||||||
|
-H "Authorization: token ${RELEASE_TOKEN}" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
--data-binary @"${file}" \
|
||||||
|
"${api_base}/releases/${release_id}/assets?name=${asset_name}"
|
||||||
|
echo "Uploaded ${asset_name}"
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user