-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (112 loc) · 3.96 KB
/
CD_release.yml
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Release CD
env:
DOCKERREPO: seblum/octivbooker
on:
workflow_dispatch:
push:
branches:
- master
paths:
- src/**
- poetry.Dockerfile
- pyproject.toml
- CHANGELOG.md
jobs:
release:
name: 🚀 Release
runs-on: ubuntu-latest
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
steps:
-
name: Checkout code
uses: actions/checkout@v4
-
name: Release
uses: googleapis/release-please-action@v4
id: release
with:
release-type: "python"
-
name: 🏷️ Tag Major and Minor Versions
if: ${{ steps.release.outputs.release_created }}
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git tag -d v${{ steps.release.outputs.major }} || true
git tag -d v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
git push origin :v${{ steps.release.outputs.major }} || true
git push origin :v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
git tag -a v${{ steps.release.outputs.major }} -m "Release v${{ steps.release.outputs.major }}"
git tag -a v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} -m "Release v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}"
git push origin v${{ steps.release.outputs.major }}
git push origin v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}
poetry-version-tag:
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
needs: release
steps:
-
name: Checkout code with full history
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
-
name: Extract tag version
id: extract_version
run: |
TAG_VERSION=$(git describe --match "v*.*.*" --tags --abbrev=0 || echo "no-tags")
echo "TAG_VERSION=$TAG_VERSION" >> $GITHUB_ENV
echo "Extracted tag version: $TAG_VERSION"
-
name: Create new Branch
run: |
git fetch origin
git checkout -b update-version-$TAG_VERSION origin/master
git pull --rebase
git push origin update-version-$TAG_VERSION --force
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Update Version in pyproject.toml
run: |
sed -i "s/^version = \".*\"/version = \"$TAG_VERSION\"/" ./pyproject.toml
-
name: Verify Update
run: cat ./pyproject.toml
-
name: Commit changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add pyproject.toml
git commit -m "Update version to $TAG_VERSION"
git push origin update-version-$TAG_VERSION
-
name: Install GitHub CLI
run: |
sudo apt-get install gh
-
name: Create Pull Request
run: |
PR_EXISTS=$(gh pr list --head update-version-$TAG_VERSION --json number --jq '.[0].number' || echo "")
if [ -z "$PR_EXISTS" ]; then
gh pr create --title "Bump version to $TAG_VERSION" \
--body "This PR updates the version in pyproject.toml to $TAG_VERSION." \
--base master \
--head update-version-$TAG_VERSION
else
echo "PR already exists."
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}