Skip to content

Commit

Permalink
tag and release on push to main
Browse files Browse the repository at this point in the history
  • Loading branch information
cameroncooper committed Sep 24, 2024
1 parent 7cfe6cf commit 0481ae6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 74 deletions.
71 changes: 64 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,71 @@ name: Release

on:
push:
tags:
- "*"

permissions:
contents: write
branches:
- main

jobs:
goreleaser:
tag:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get latest tag
id: get_latest_tag
run: |
# Fetch all tags from the remote
git fetch --tags
# Get the latest tag from git
latest_tag=$(git describe --tags --abbrev=0 --match "v*")
echo "Latest tag: $latest_tag"
# If there are no tags, start from v0.0.0
if [ -z "$latest_tag" ]; then
echo "v0.0.0" > latest_tag.txt
else
echo "$latest_tag" > latest_tag.txt
fi
- name: Increment version
id: increment_version
run: |
latest_tag=$(cat latest_tag.txt)
# Remove the 'v' from the version to work with the numbers
version_without_v=${latest_tag#v}
# Split the tag into major, minor, and patch versions
IFS='.' read -r -a version_parts <<< "$version_without_v"
major=${version_parts[0]}
minor=${version_parts[1]}
patch=${version_parts[2]}
# Increment the patch version
new_patch=$((patch + 1))
new_version="v$major.$minor.$new_patch"
echo "New version: $new_version"
# Save the new version to the GitHub environment to be used in future steps
echo "new_version=$new_version" >> $GITHUB_ENV
- name: Create and push new tag
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
run: |
new_version=${{ env.new_version }}
# Create a new tag
git tag "$new_version"
# Push the new tag to the remote repository
git push origin "$new_version"
release:
needs: tag
runs-on: ubuntu-latest
environment: goreleaser
steps:
Expand All @@ -28,4 +85,4 @@ jobs:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
67 changes: 0 additions & 67 deletions .github/workflows/tag-release.yml

This file was deleted.

0 comments on commit 0481ae6

Please sign in to comment.