99 lines
3.2 KiB
YAML
99 lines
3.2 KiB
YAML
name: Test and Release PawSQL
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
env:
|
|
REPO_URL: https://cloud.campbellwireless.net/git/${{ github.repository }}.git
|
|
run: |
|
|
set -eux
|
|
git init .
|
|
git remote add origin "$REPO_URL"
|
|
auth="$(printf '%s' '${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}' | base64 | tr -d '\n')"
|
|
git config --local http.https://cloud.campbellwireless.net/.extraheader "AUTHORIZATION: basic $auth"
|
|
git fetch --prune --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
|
|
git checkout --detach "${{ github.sha }}"
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go.mod
|
|
|
|
- name: Test PawSQL
|
|
run: go test ./...
|
|
|
|
release:
|
|
if: ${{ github.event_name == 'push' }}
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout full history
|
|
env:
|
|
REPO_URL: https://cloud.campbellwireless.net/git/${{ github.repository }}.git
|
|
run: |
|
|
set -eux
|
|
git init .
|
|
git remote add origin "$REPO_URL"
|
|
auth="$(printf '%s' '${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}' | base64 | tr -d '\n')"
|
|
git config --local http.https://cloud.campbellwireless.net/.extraheader "AUTHORIZATION: basic $auth"
|
|
git fetch --prune --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
|
|
git checkout --detach "${{ github.sha }}"
|
|
|
|
- name: Determine semantic version
|
|
id: version
|
|
run: |
|
|
set -eu
|
|
previous="$(git tag -l 'v[0-9]*' --sort=-v:refname | head -n1)"
|
|
range=HEAD
|
|
if [ -n "$previous" ]; then
|
|
range="${previous}..HEAD"
|
|
fi
|
|
messages="$(git log --format='%B%n---commit---' "$range")"
|
|
if [ -z "$messages" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
bump=""
|
|
if printf '%s\n' "$messages" | grep -Eq '(^[a-z]+(\([^)]+\))?!:|BREAKING CHANGE:)'; then
|
|
bump=major
|
|
elif printf '%s\n' "$messages" | grep -Eq '^feat(\([^)]+\))?:'; then
|
|
bump=minor
|
|
elif printf '%s\n' "$messages" | grep -Eq '^(fix|perf)(\([^)]+\))?:'; then
|
|
bump=patch
|
|
else
|
|
exit 0
|
|
fi
|
|
|
|
version="${previous#v}"
|
|
if [ -z "$version" ]; then
|
|
version=0.0.0
|
|
fi
|
|
IFS=. read -r major minor patch <<EOF
|
|
$version
|
|
EOF
|
|
case "$bump" in
|
|
major) major=$((major + 1)); minor=0; patch=0 ;;
|
|
minor) minor=$((minor + 1)); patch=0 ;;
|
|
patch) patch=$((patch + 1)) ;;
|
|
esac
|
|
echo "tag=v${major}.${minor}.${patch}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Create and push version tag
|
|
if: ${{ steps.version.outputs.tag != '' }}
|
|
env:
|
|
TAG: ${{ steps.version.outputs.tag }}
|
|
run: |
|
|
set -eu
|
|
git config user.name "Gitea Actions"
|
|
git config user.email "actions@campbellwireless.net"
|
|
git tag --annotate "$TAG" --message "Release $TAG"
|
|
git push origin "$TAG"
|