-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: automatically create a release if pyproject.toml is updated and t…
…he version is not already tagged (#85) This Action should run each time `pyproject.toml` is updated on `main` It will obtain the version number from `pyproject.toml` It will check that version number to ensure isn't already a Tag It will create the Tag and Release if it doesn't exist
- Loading branch information
1 parent
56d8e03
commit 1ee6c4f
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Release on pyproject.toml Update | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- "pyproject.toml" | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Extract version from pyproject.toml | ||
id: extract_version | ||
run: | | ||
VERSION=$(grep '^version =' pyproject.toml | awk -F' = ' '{print $2}' | tr -d '"') | ||
echo "::set-output name=version::$VERSION" | ||
- name: Check if tag exists | ||
id: check_tag | ||
uses: actions/github-script@v4 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const tagName = 'v${{ steps.extract_version.outputs.version }}'; | ||
const { data: tags } = await github.git.listMatchingRefs({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
ref: `tags/${tagName}` | ||
}); | ||
if (tags.length > 0) { | ||
console.log(`Tag ${tagName} already exists. Skipping release creation.`); | ||
core.setOutput('tag_exists', 'true'); | ||
} else { | ||
console.log(`Tag ${tagName} does not exist. Proceeding with release creation.`); | ||
core.setOutput('tag_exists', 'false'); | ||
} | ||
- name: Create Release | ||
if: steps.check_tag.outputs.tag_exists == 'false' | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: v${{ steps.extract_version.outputs.version }} | ||
release_name: Release v${{ steps.extract_version.outputs.version }} | ||
draft: false | ||
prerelease: false |