- Add lint, formatting, vet, and publish workflow checks - Run Go database tests with PostgreSQL and add Java tests - Make consumer sync opt-in; update docs and Go dependency
90 lines
2.9 KiB
YAML
90 lines
2.9 KiB
YAML
name: Publish Go package
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'backend/v*'
|
|
release:
|
|
types:
|
|
- published
|
|
|
|
jobs:
|
|
publish:
|
|
name: Publish shared Go module
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
- name: Checkout source
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: backend/go.mod
|
|
cache: false
|
|
|
|
- name: Check formatting and vet the Go module
|
|
working-directory: backend
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
mapfile -d '' go_files < <(find . -type f -name '*.go' -print0)
|
|
if ((${#go_files[@]})); then
|
|
test -z "$(gofmt -l "${go_files[@]}")"
|
|
fi
|
|
go vet ./...
|
|
|
|
- name: Test Go module
|
|
working-directory: backend
|
|
run: go test ./...
|
|
|
|
- name: Install ZIP tools
|
|
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y zip
|
|
|
|
- name: Package Go module
|
|
env:
|
|
RELEASE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || github.ref_name }}
|
|
run: |
|
|
package_directory='gitea-go-package'
|
|
rm -rf "$package_directory"
|
|
mkdir -p "$package_directory"
|
|
bash scripts/package-go-module.sh "$RELEASE_TAG" "$package_directory"
|
|
find "$package_directory" -maxdepth 1 -type f -name '*.zip' -print -quit | grep -q .
|
|
|
|
- name: Publish to Gitea Package Registry
|
|
env:
|
|
PACKAGE_REGISTRY_USERNAME: ${{ secrets.PACKAGE_REGISTRY_USERNAME }}
|
|
PACKAGE_REGISTRY_TOKEN: ${{ secrets.PACKAGE_REGISTRY_TOKEN }}
|
|
GITEA_GO_REGISTRY: https://repos.gfranz.ch/api/packages/Gabriel20xx/go/upload
|
|
run: |
|
|
set -euo pipefail
|
|
if [ -z "$PACKAGE_REGISTRY_USERNAME" ] || [ -z "$PACKAGE_REGISTRY_TOKEN" ]; then
|
|
echo 'PACKAGE_REGISTRY_USERNAME and PACKAGE_REGISTRY_TOKEN secrets are required.' >&2
|
|
exit 1
|
|
fi
|
|
package_file="$(find gitea-go-package -maxdepth 1 -type f -name '*.zip' -print -quit)"
|
|
test -n "$package_file"
|
|
response_file="$(mktemp)"
|
|
http_status="$(curl --silent --show-error --fail-with-body \
|
|
--user "$PACKAGE_REGISTRY_USERNAME:$PACKAGE_REGISTRY_TOKEN" \
|
|
--output "$response_file" \
|
|
--write-out '%{http_code}' \
|
|
--upload-file "$package_file" \
|
|
"$GITEA_GO_REGISTRY" || true)"
|
|
case "$http_status" in
|
|
201)
|
|
echo 'Go package published.'
|
|
;;
|
|
409)
|
|
echo 'Go package version already exists; leaving the immutable package unchanged.'
|
|
;;
|
|
*)
|
|
cat "$response_file" >&2
|
|
echo "Gitea Go package upload failed with HTTP status $http_status." >&2
|
|
exit 1
|
|
;;
|
|
esac
|