Skip to content

Commit

Permalink
fix(ci): solve the problem that tag made by workflow cannot trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Peterka committed Feb 8, 2024
1 parent 1361967 commit 2de1fa1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
40 changes: 24 additions & 16 deletions .github/workflows/release-python.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,51 @@
name: "[auto] release-python"

on:
push:
tags:
- v*
workflow_dispatch: # be able to manually re-run
workflow_run:
workflows: ["Release"]
types:
- completed

env:
PYTHON_VERSION: "3.10"
PYTHON_VERSION: "3.11"

jobs:
build:
release:
name: Release new version to PyPI
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-tags: 'true'

- name: Check version format vMAJOR.MINOR.PATCH(-SUFFIX)
id: version
run: |
if [[ ! "$GITHUB_REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?$ ]]; then
echo "Invalid version format. Expected vMAJOR.MINOR.PATCH(-SUFFIX)?, got ${GITHUB_REF_NAME}"
RELEASE_TAG=$(git tag --points-at HEAD)
echo "RELEASE_TAG: $RELEASE_TAG"
if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?$ ]]; then
echo "Invalid version format. Expected vMAJOR.MINOR.PATCH(-SUFFIX)?, got ${RELEASE_TAG}"
exit 1
fi
echo "version=${RELEASE_TAG#v}" >> $GITHUB_OUTPUT
- name: Checkout repository
uses: actions/checkout@v4

- name: Install the project
- name: Release
uses: dronetag/actions/release-python@main
with:
pypi_name: dronetag
pypi_host: ${{ secrets.PRIV_PIP_HOST }}
pypi_user: ${{ secrets.PRIV_PIP_USER }}
pypi_pass: ${{ secrets.PRIV_PIP_PASSWORD }}
version: "${GITHUB_REF_NAME#v}"
version: ${{ steps.version.outputs.version }}

- name: Commit version on release branch
run: |
if [[ $(git rev-parse heads/main) = $(git rev-parse ${GITHUB_REF}) ]]; then
echo "We are at the top of main branch so we can commit the version bump"
git checkout main
if [[ $(git rev-parse heads/main) = $(git rev-parse HEAD) ]]; then
git checkout main # in case we are on tag
sed -i "s/version = .*/version = \"${{ steps.version.outputs.version }}\"/g" pyproject.toml
git add pyproject.toml
git commit -m "Release ${GITHUB_REF_NAME#v} [skip ci]"
git commit -m "Release ${{ steps.version.outputs.version }} [skip ci]"
git push
fi
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "RELEASE"
name: "Release"

on:
workflow_dispatch:
Expand All @@ -16,8 +16,9 @@ jobs:
uses: dronetag/actions/get-next-version@main
id: get-next-version

- name: Create the tag
- name: Create the tag (if it does not exist yet)
run: |
git show-ref --tags --verify --quiet "refs/tags/v${{ steps.get-next-version.outputs.version }}" && exit 0
git config --local user.email "" && git config --local user.name "GitHub Action"
git tag v${{ steps.get-next-version.outputs.version }}
git push origin v${{ steps.get-next-version.outputs.version }}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools >= 61.0"]
requires = ["setuptools >= 59.0"]
build-backend = "setuptools.build_meta"

[project]
Expand Down

0 comments on commit 2de1fa1

Please sign in to comment.