Skip to content

Merge pull request #31 from origadmin/dev #30

Merge pull request #31 from origadmin/dev

Merge pull request #31 from origadmin/dev #30

name: Auto Tagging And Release After Tests
on:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
with:
ref: main
fetch-depth: 0 # Fetch all history
- name: Set up Go
uses: actions/[email protected]
with:
go-version: stable
- name: Run tests
run: |
go test -race -v ./...
tagging:
needs: [ test ]
if: success()
runs-on: ubuntu-latest
permissions:
contents: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout code
uses: actions/[email protected]
with:
ref: main
fetch-depth: 0 # Fetch all history
- name: Get latest release
id: get_latest_release
run: |
LATEST_RELEASE=$(curl -s -H "Authorization: token ${{ env.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name')
echo "LATEST_RELEASE=$LATEST_RELEASE" >> $GITHUB_OUTPUT
- name: Determine next version
id: determine_next_version
run: |
chmod +x ./scripts/git/release.sh
HEAD_TAG=$(./scripts/git/release.sh get_head_version_tag .)
NEXT_TAG=$(./scripts/git/release.sh get_next_module_version .)
echo "HEAD_TAG=$HEAD_TAG"
echo "HEAD_TAG=$HEAD_TAG" >> $GITHUB_OUTPUT
echo "NEXT_TAG=$NEXT_TAG"
echo "NEXT_TAG=$NEXT_TAG" >> $GITHUB_OUTPUT
- name: Generate changelog
id: generate_changelog
run: |
LATEST_RELEASE=${{ steps.get_latest_release.outputs.LATEST_RELEASE }}
echo "# Changelog" > changelog.txt
if [[ -z "$LATEST_RELEASE" ]]; then
# If there's no previous release, get only the current commit's log
git config --global core.pager cat
# git log --pretty=format:"* %s **by** @%an"
git log --pretty=format:"* %s **by** @%an" >> changelog.txt
else
# Get all submission information since the last release
CHANGELOG=$(git log "$LATEST_RELEASE"..HEAD --pretty=format:"* %s **by** @%an")
git log "$LATEST_RELEASE"..HEAD --pretty=format:"* %s **by** @%an" >> changelog.txt
fi
- name: Create release
if: ${{ !steps.determine_next_version.outputs.HEAD_TAG }}
uses: softprops/[email protected]
with:
tag_name: ${{ steps.determine_next_version.outputs.NEXT_TAG }}
name: Release ${{ steps.determine_next_version.outputs.NEXT_TAG }}
body_path: changelog.txt
draft: false
prerelease: false
# # Skip this step if HEAD_TAG is not empty, Because the commit is tagged for the submodule
# - name: Create release (only if HEAD_TAG exists)
# if: ${{ steps.determine_next_version.outputs.HEAD_TAG }}
# uses: softprops/action-gh-release@v1
# with:
# name: Release ${{ steps.determine_next_version.outputs.NEXT_TAG }}
# body_path: changelog.txt
# draft: false
# prerelease: false
release:
needs: [ tagging ]
if: success()
runs-on: ubuntu-latest
permissions:
contents: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/[email protected] # v5
with:
go-version: stable
- name: Ensure Go
run: go version
- name: Checkout code
uses: actions/[email protected] # v4
with:
ref: main
fetch-depth: 0 # Fetch all history
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
if: success()
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: '~> v2'
args: release --clean -f ./cmd/protoc-gen-go-gins/.goreleaser.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Upload assets
# uses: actions/[email protected]
# with:
# name: protoc-gen-go-gins
# path: ./cmd/protoc-gen-go-gins/dist/*