-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (60 loc) · 2.46 KB
/
tag.yml
File metadata and controls
68 lines (60 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Tag
on:
workflow_run:
workflows: ["CI"]
types: [completed]
branches: [main]
jobs:
tag:
# Only run if CI succeeded and was triggered by push (not PR)
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push'
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Check version status
id: version
run: |
# Get current version
CURRENT_VERSION=$(grep -m1 'version = ' pyproject.toml | cut -d'"' -f2)
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Check if version is already published on PyPI
if curl -s "https://pypi.org/pypi/django-cachex-ng/$CURRENT_VERSION/json" | grep -q '"version"'; then
echo "on_pypi=true" >> $GITHUB_OUTPUT
echo "Version $CURRENT_VERSION already published on PyPI"
else
echo "on_pypi=false" >> $GITHUB_OUTPUT
echo "Version $CURRENT_VERSION not on PyPI"
fi
# Check if tag already exists (fetch tags first)
git fetch --tags
if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
echo "tag_exists=true" >> $GITHUB_OUTPUT
echo "Tag v$CURRENT_VERSION already exists"
else
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "Tag v$CURRENT_VERSION does not exist"
fi
- name: Create and push tag
if: steps.version.outputs.on_pypi == 'false' && steps.version.outputs.tag_exists == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "v${{ steps.version.outputs.current }}"
git push origin "v${{ steps.version.outputs.current }}"
- name: Trigger publish workflow
if: steps.version.outputs.on_pypi == 'false'
run: gh workflow run publish.yml -f version=${{ steps.version.outputs.current }} -R ${{ github.repository }}
env:
GH_TOKEN: ${{ github.token }}
- name: Trigger docs workflow for new tag
if: steps.version.outputs.on_pypi == 'false' && steps.version.outputs.tag_exists == 'false'
run: gh workflow run docs.yml --ref "v${{ steps.version.outputs.current }}" -R ${{ github.repository }}
env:
GH_TOKEN: ${{ github.token }}