Chore: Create release on PR merge #2
Workflow file for this run
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: Merge | |
on: | |
pull_request: | |
types: | |
- closed | |
jobs: | |
release: | |
name: Release | |
if: github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Git | |
run: | | |
git config --global user.name "Emmanuel King Kasulani" | |
git config --global user.email "kasulani@gmail.com" | |
- name: Get the latest tag | |
id: get-latest-tag | |
run: | | |
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) || echo "v0.0.0") | |
echo "latest_tag=$latest_tag" >> $GITHUB_ENV | |
echo "tag: $latest_tag" | |
- name: Determine next version | |
id: determine-version | |
run: | | |
# Extract the branch prefix from the PR's base ref | |
branch="${{ github.event.pull_request.head.ref }}" | |
echo "Branch: $branch" | |
latest_tag="${{ env.latest_tag }}" | |
IFS='.' read -r major minor patch <<< "${latest_tag#v}" | |
if [[ $branch == "minor/"* ]]; then | |
minor=$((minor + 1)) | |
patch=0 | |
elif [[ $branch == "patch/"* ]]; then | |
patch=$((patch + 1)) | |
elif [[ $branch == "major/"* ]]; then | |
major=$((major + 1)) | |
minor=0 | |
patch=0 | |
else | |
echo "Branch prefix '$branch' does not affect versioning. Skipping release." | |
exit 0 | |
fi | |
new_tag="v$major.$minor.$patch" | |
echo "new_tag=$new_tag" >> $GITHUB_ENV | |
echo "Determined new version: $new_tag" | |
- name: Create tag | |
run: | | |
git tag "${{ env.new_tag }}" | |
git push origin "${{ env.new_tag }}" | |
- name: Run GoReleaser | |
uses: goreleaser/goreleaser-action@v6 | |
with: | |
version: latest | |
args: release --clean | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |