Skip to content

Commit c3d9a4f

Browse files
Merge pull request #1981 from kili-technology/chore/smooth-release
chore: use a dedicated user to push tag
2 parents 13926e7 + 9788488 commit c3d9a4f

File tree

2 files changed

+48
-49
lines changed

2 files changed

+48
-49
lines changed

.github/workflows/pre_release.yml

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
name: Pre-release - Bump version & draft release
2+
23
on:
34
workflow_dispatch:
45
inputs:
56
target_branch:
67
description: >
78
"This workflow will create a commit to bump version on a branch.
8-
Enter the target branch: main for Saas, or release/XX.Y for a LTS version: "
9+
Enter the target branch: main for SaaS, or release/XX.Y for an LTS version: "
910
required: true
1011
type: string
1112
default: "main"
1213

14+
permissions:
15+
contents: write
16+
1317
jobs:
1418
pre_release:
1519
runs-on: ubuntu-latest
1620
name: Bump version & draft release
21+
1722
steps:
18-
- uses: actions/checkout@v4
23+
- name: Checkout target branch
24+
uses: actions/checkout@v4
1925
with:
20-
ref: ${{ github.event.inputs.target_branch}}
26+
ref: ${{ github.event.inputs.target_branch }}
27+
token: ${{ secrets.RELEASE_BOT_PAT }} # <<< service PAT
2128

2229
- name: Set up Python
2330
uses: actions/setup-python@v5
@@ -32,49 +39,63 @@ jobs:
3239
3340
- name: Set git identity
3441
run: |
35-
git config user.name github-actions
36-
git config user.email github-actions@github.com
42+
git config user.name "kili-release-bot"
43+
git config user.email "[email protected].github.com"
3744
3845
- name: Add the bump commit
46+
env:
47+
GH_TOKEN: ${{ secrets.RELEASE_BOT_PAT }}
48+
shell: bash
3949
run: |
50+
set -euo pipefail
51+
4052
git fetch --quiet
4153
4254
curl https://raw.githubusercontent.com/kili-technology/kili-python-sdk/main/.github/scripts/utils.sh --output utils.sh
43-
source ./utils.sh # to get the bump_version function
55+
source ./utils.sh # exposes bump_version
4456
45-
# create bump commit
57+
# create bump commit (major / minor / patch)
4658
new_version=$(bump_version commit patch)
4759
echo "New version (bump_version): $new_version"
4860
49-
git push
50-
env:
51-
GH_TOKEN: ${{ github.token }} # needed for gh cli
61+
# Push back to the same branch explicitly
62+
git push origin HEAD:${{ github.event.inputs.target_branch }}
5263
53-
- name: create draft release
64+
- name: Create tag and draft release
65+
env:
66+
GH_TOKEN: ${{ secrets.RELEASE_BOT_PAT }} # used by gh CLI
67+
shell: bash
5468
run: |
69+
set -euo pipefail
70+
5571
curl https://raw.githubusercontent.com/kili-technology/kili-python-sdk/main/.github/scripts/utils.sh --output utils.sh
56-
source ./utils.sh # to get the get_sdk_version_from_pyproject_toml function
72+
source ./utils.sh
5773
58-
# Get release version
74+
# Get release version from pyproject.toml (now bumped)
5975
release_version=$(get_sdk_version_from_pyproject_toml)
6076
echo "Release version: $release_version"
6177
62-
# tag and push the tag
63-
# -a to create an annotated tag
64-
git fetch --quiet
65-
git tag -a $release_version -m "Release $release_version"
66-
git push origin $release_version
78+
# Get last release tag for release notes range
79+
latest_release=$(get_last_release_tag_github)
80+
echo "Latest release tag: $latest_release"
6781
68-
# create draft release
69-
link_to_draft=$(gh release create $release_version --draft --title "Release $release_version" --generate-notes --notes-start-tag $latest_release)
70-
echo "Link to draft release: $link_to_draft"
82+
git fetch --tags --quiet
83+
84+
# Create annotated tag on this commit & push it
85+
git tag -a "$release_version" -m "Release $release_version"
86+
git push origin "$release_version"
7187
72-
# filter the result to get the link
73-
# will match any string that starts with https:// and contains any number of characters that are not spaces.
88+
# Create draft release
89+
link_to_draft=$(gh release create "$release_version" \
90+
--draft \
91+
--title "Release $release_version" \
92+
--generate-notes \
93+
--notes-start-tag "$latest_release")
94+
95+
# Extract URL from gh output
7496
link_to_draft=$(echo "$link_to_draft" | grep -o 'https://[^ ]*')
97+
7598
echo "Link to draft release: $link_to_draft"
7699
77-
echo "LINK_TO_DRAFT=$link_to_draft" >> $GITHUB_ENV
78-
echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV
79-
env:
80-
GH_TOKEN: ${{ github.token }} # needed for gh cli
100+
echo "LINK_TO_DRAFT=$link_to_draft" >> "$GITHUB_ENV"
101+
echo "RELEASE_VERSION=$release_version" >> "$GITHUB_ENV"

.github/workflows/release.yml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ jobs:
1010
permissions:
1111
# needed to publish to PyPI
1212
id-token: write
13-
# needed to create a PR to merge the release branch and main
14-
contents: write
15-
pull-requests: write
1613
steps:
1714
- uses: actions/checkout@v4
1815

@@ -82,25 +79,6 @@ jobs:
8279
git config user.name github-actions
8380
git config user.email [email protected]
8481
85-
- name: create PR to merge release branch and main
86-
run: |
87-
git fetch --quiet
88-
89-
# ${{ github.ref_name }}: The short ref name of the branch or tag that triggered the workflow run.
90-
git checkout ${{ github.ref_name }}
91-
92-
curl https://raw.githubusercontent.com/kili-technology/kili-python-sdk/main/.github/scripts/utils.sh --output utils.sh
93-
source ./utils.sh # to get the bump_version function
94-
95-
sdk_version=$(get_sdk_version_from_pyproject_toml)
96-
97-
# create a branch to merge the release branch and main
98-
git checkout -b merge_release/$sdk_version
99-
git push --set-upstream origin merge_release/$sdk_version
100-
gh pr create --title "chore: merge release/$sdk_version into main" --body "Merge release/$sdk_version into main" --base main
101-
env:
102-
GH_TOKEN: ${{ github.token }} # needed for gh cli
103-
10482
deploy-documentation:
10583
uses: ./.github/workflows/deploy_doc.yml
10684
needs: [publish] # Run after the previous job

0 commit comments

Comments
 (0)