Skip to content

Commit

Permalink
πŸš€ Add auto-release workflow for versioned releases
Browse files Browse the repository at this point in the history
πŸ“¦ This commit introduces a new GitHub Actions workflow for automatic releases:

- ✨ Creates a new `.github/workflows/auto-release.yml` file
- 🏷️ Triggers on push of version tags (v*)
- πŸ”„ Generates changelog from commits since last tag
- πŸ“Š Creates/updates a base release for major versions
- πŸŽ‰ Creates a full version release with detailed changelog
- πŸ› οΈ Updates `action.yml` to use bash shell for Git setup

This automation streamlines the release process, ensuring consistent and informative releases for each new version of the project.
  • Loading branch information
yuri-val committed Oct 18, 2024
1 parent e7500f5 commit 5536ef9
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Auto Release

on:
push:
tags:
- 'v*'

permissions:
contents: write

jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get tag name
id: get_tag
shell: bash
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

- name: Get base version
id: get_base_version
shell: bash
run: |
BASE_VERSION=$(echo ${{ steps.get_tag.outputs.TAG }} | cut -d. -f1)
echo "BASE_VERSION=${BASE_VERSION}" >> $GITHUB_OUTPUT
- name: Get previous tag
id: get_previous_tag
shell: bash
run: |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 ${{ steps.get_tag.outputs.TAG }}^ || echo "")
echo "PREVIOUS_TAG=${PREVIOUS_TAG}" >> $GITHUB_OUTPUT
- name: Generate changelog
id: generate_changelog
shell: bash
run: |
if [ -n "${{ steps.get_previous_tag.outputs.PREVIOUS_TAG }}" ]; then
CHANGELOG=$(git log --pretty=format:"- %s" ${{ steps.get_previous_tag.outputs.PREVIOUS_TAG }}..${{ steps.get_tag.outputs.TAG }})
else
CHANGELOG=$(git log --pretty=format:"- %s" ${{ steps.get_tag.outputs.TAG }})
fi
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create or Update Base Release
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const baseVersion = '${{ steps.get_base_version.outputs.BASE_VERSION }}';
const fullVersion = '${{ steps.get_tag.outputs.TAG }}';
const changelog = `${{ steps.generate_changelog.outputs.CHANGELOG }}`;
try {
// Try to get the existing release
await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: baseVersion
});
// If it exists, update it
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
tag_name: baseVersion,
name: `Base Release ${baseVersion}`,
body: `This is the base release for ${baseVersion}. Latest version: ${fullVersion}\n\nChangelog:\n${changelog}`,
draft: false,
prerelease: false
});
} catch (error) {
if (error.status === 404) {
// If it doesn't exist, create it
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: baseVersion,
name: `Base Release ${baseVersion}`,
body: `This is the base release for ${baseVersion}. Latest version: ${fullVersion}\n\nChangelog:\n${changelog}`,
draft: false,
prerelease: false
});
} else {
throw error;
}
}
- name: Create Full Version Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_tag.outputs.TAG }}
release_name: Release ${{ steps.get_tag.outputs.TAG }}
body: |
Changes in this Release:
${{ steps.generate_changelog.outputs.CHANGELOG }}
draft: false
prerelease: false
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ runs:
ref: ${{ inputs.dev_branch }}

- name: Set up Git
shell: bash
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
Expand Down

0 comments on commit 5536ef9

Please sign in to comment.