Bump version to 1.0.4 #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tag and Release | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
tag: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.PAT_TOKEN }} | |
- name: Set up Git | |
run: | | |
git config --global user.name 'GitHub Actions' | |
git config --global user.email '[email protected]' | |
- name: Get the current version from file | |
id: vars | |
run: | | |
VERSION=$(cat VERSION) | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Check if the current version is already tagged | |
id: check_tag | |
run: | | |
if git rev-parse "v$VERSION" >/dev/null 2>&1; then | |
echo "use_tag=true" >> $GITHUB_ENV | |
else | |
echo "use_tag=false" >> $GITHUB_ENV | |
fi | |
- name: Increment version if necessary | |
id: increment_version | |
run: | | |
if [ "$use_tag" == "true" ]; then | |
new_version="$VERSION" | |
else | |
IFS='.' read -r major minor patch <<< "$VERSION" | |
new_patch=$((patch + 1)) | |
new_version="$major.$minor.$new_patch" | |
fi | |
echo "new_version=$new_version" >> $GITHUB_ENV | |
- name: Set Up Remote URL with PAT | |
run: | | |
git remote set-url origin https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git | |
git remote -v # Print the current remote URL configuration | |
- name: Create and Push Tag | |
run: | | |
git tag "v$new_version" | |
echo "Pushing tag v$new_version" | |
git push https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git "v$new_version" | |
- name: Update VERSION file (if version was incremented) | |
if: env.use_tag == 'false' | |
run: | | |
echo $new_version > VERSION | |
git add VERSION | |
git commit -m "Bump version to $new_version" | |
git push https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git main | |
release: | |
runs-on: ubuntu-latest | |
needs: tag | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.PAT_TOKEN }} | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.23' | |
- name: Cache Go Modules | |
id: cache-modules | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cache/go-build | |
~/go/pkg/mod | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go- | |
- name: Install dependencies | |
run: go mod download | |
- name: Run tests | |
run: go test -v ./... | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
with: | |
tag_name: "v$new_version" | |
release_name: "Release v$new_version" | |
body: | | |
Changes in this release: | |
- TODO: Add release notes here | |
draft: false | |
prerelease: false |