From a7e4c501e4643c2b0e5377136b7b8dcd2e180960 Mon Sep 17 00:00:00 2001 From: Micheal Wilkinson Date: Fri, 20 Mar 2026 09:37:09 +0000 Subject: [PATCH] ci(gitea): add validation and release workflows --- .gitea/workflows/pr-merge-validation.yml | 27 ++++++ .gitea/workflows/pr-validation.yml | 26 ++++++ .gitea/workflows/push-unit-tests.yml | 23 +++++ .gitea/workflows/tag-build-artifacts.yml | 107 +++++++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 .gitea/workflows/pr-merge-validation.yml create mode 100644 .gitea/workflows/pr-validation.yml create mode 100644 .gitea/workflows/push-unit-tests.yml create mode 100644 .gitea/workflows/tag-build-artifacts.yml diff --git a/.gitea/workflows/pr-merge-validation.yml b/.gitea/workflows/pr-merge-validation.yml new file mode 100644 index 0000000..38b13f9 --- /dev/null +++ b/.gitea/workflows/pr-merge-validation.yml @@ -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 diff --git a/.gitea/workflows/pr-validation.yml b/.gitea/workflows/pr-validation.yml new file mode 100644 index 0000000..106a130 --- /dev/null +++ b/.gitea/workflows/pr-validation.yml @@ -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 diff --git a/.gitea/workflows/push-unit-tests.yml b/.gitea/workflows/push-unit-tests.yml new file mode 100644 index 0000000..8a84b65 --- /dev/null +++ b/.gitea/workflows/push-unit-tests.yml @@ -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 ./... diff --git a/.gitea/workflows/tag-build-artifacts.yml b/.gitea/workflows/tag-build-artifacts.yml new file mode 100644 index 0000000..d1d633a --- /dev/null +++ b/.gitea/workflows/tag-build-artifacts.yml @@ -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