Skip to content

Commit 8b01dfd

Browse files
authored
chore: trying to fix the issue with existing tags since we do not have develop aymore
1 parent 1edb081 commit 8b01dfd

File tree

2 files changed

+123
-49
lines changed

2 files changed

+123
-49
lines changed
Lines changed: 90 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
# yamllint disable rule:truthy
3-
name: "Push on main/stable"
3+
name: "Push on main"
44

55
on:
66
push:
@@ -10,86 +10,131 @@ on:
1010
paths-ignore:
1111
- 'docs/**'
1212

13+
permissions:
14+
contents: write
15+
1316
jobs:
1417
check_commit:
1518
runs-on: ubuntu-latest
1619
outputs:
17-
skip: ${{ steps.filter.outputs.skip }}
20+
skip: ${{ steps.decide.outputs.skip }}
21+
reason: ${{ steps.decide.outputs.reason }}
22+
next_version: ${{ steps.version.outputs.next-version }}
23+
previous_tag: ${{ steps.previoustag.outputs.tag }}
1824
steps:
1925
- uses: actions/checkout@v5
2026
with:
21-
fetch-depth: 2 # Fetches the commit history for the last 2 commits
22-
- id: filter
27+
token: ${{ secrets.GH_INFRAHUB_BOT_TOKEN }}
28+
fetch-depth: 0
29+
30+
- id: commit_meta
31+
shell: bash
2332
run: |
24-
commit_author=$(git log -1 --pretty=format:'%an')
25-
commit_message=$(git log -1 --pretty=format:'%s')
26-
if [[ "$commit_author" == "opsmill-bot" && \
27-
"$commit_message" == "chore: update pyproject.toml & galaxy.yml" ]]; then
28-
echo "skip=true" >> $GITHUB_OUTPUT
29-
else
30-
echo "skip=false" >> $GITHUB_OUTPUT
33+
echo "author=$(git log -1 --pretty=format:'%an')" >> $GITHUB_OUTPUT
34+
echo "message=$(git log -1 --pretty=format:'%s')" >> $GITHUB_OUTPUT
35+
36+
# Your three steps, kept here:
37+
- name: Get previous tag
38+
id: previoustag
39+
uses: WyriHaximus/github-action-get-previous-tag@v1
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Calculate next version
44+
id: version
45+
uses: patrickjahns/[email protected]
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
49+
# Decide whether to skip downstream work:
50+
- id: decide
51+
shell: bash
52+
run: |
53+
set -euo pipefail
54+
skip=false
55+
reason=""
56+
57+
author='${{ steps.commit_meta.outputs.author }}'
58+
msg='${{ steps.commit_meta.outputs.message }}'
59+
prev='${{ steps.previoustag.outputs.tag }}'
60+
next='${{ steps.version.outputs.next-version }}'
61+
62+
# Skip on bot housekeeping commits
63+
if [[ "$author" == "opsmill-bot" ]] && [[ "$msg" =~ ^chore(:|\(release\):) ]]; then
64+
skip=true
65+
reason="bot-commit"
3166
fi
3267
68+
# Skip when there is no new version to cut
69+
if [[ "$next" == "$prev" || -z "$next" ]]; then
70+
skip=true
71+
reason="${reason:+$reason,}no-new-version"
72+
fi
73+
74+
echo "skip=$skip" >> $GITHUB_OUTPUT
75+
echo "reason=$reason" >> $GITHUB_OUTPUT
76+
3377
prepare_release:
3478
needs: check_commit
3579
if: needs.check_commit.outputs.skip == 'false'
3680
runs-on: ubuntu-22.04
3781
outputs:
38-
next_version: ${{ steps.version.outputs.next-version }}
82+
head_sha: ${{ steps.head.outputs.sha }}
83+
next_version: ${{ steps.expose.outputs.next_version }}
3984
steps:
40-
- name: "Set up Python"
41-
uses: "actions/setup-python@v5"
85+
- uses: actions/checkout@v5
86+
with:
87+
token: ${{ secrets.GH_INFRAHUB_BOT_TOKEN }}
88+
fetch-depth: 0
89+
90+
- name: Set up Python
91+
uses: actions/setup-python@v5
4292
with:
4393
python-version: "3.11"
4494

45-
- name: "Install Poetry"
46-
uses: "snok/install-poetry@v1"
95+
- name: Install Poetry
96+
uses: snok/install-poetry@v1
4797
with:
4898
version: 2.1.3
4999
virtualenvs-create: true
50100
virtualenvs-in-project: true
51101
installer-parallel: true
52102

53-
- uses: actions/checkout@v5
54-
with:
55-
token: ${{ secrets.GH_INFRAHUB_BOT_TOKEN }}
56-
fetch-depth: 0
57-
58-
- name: Get Previous tag
59-
id: previoustag
60-
uses: "WyriHaximus/github-action-get-previous-tag@master"
61-
env:
62-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
63-
64-
- name: Calculate next version
65-
id: version
66-
uses: patrickjahns/[email protected]
67-
env:
68-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69-
70103
- name: Update pyproject.toml versions
104+
env:
105+
VERSION: ${{ needs.check_commit.outputs.next_version }}
71106
run: |
72-
VERSION=${{ steps.version.outputs.next-version }}
73107
echo "Updating to version $VERSION"
74-
poetry version $VERSION # directly use the VERSION
108+
poetry version "$VERSION"
75109
76110
- name: Update lock file
77111
run: poetry lock
78112

79-
- name: commit pyproject.toml
80-
uses: github-actions-x/[email protected]
81-
with:
82-
github-token: ${{ secrets.GH_INFRAHUB_BOT_TOKEN }}
83-
push-branch: 'main'
84-
commit-message: 'chore: update pyproject.toml'
85-
files: pyproject.toml poetry.lock
86-
name: opsmill-bot
87-
88-
rebase: true
113+
- name: Commit version bump (skip CI)
114+
env:
115+
VERSION: ${{ needs.check_commit.outputs.next_version }}
116+
run: |
117+
git config user.name "opsmill-bot"
118+
git config user.email "[email protected]"
119+
git add pyproject.toml poetry.lock
120+
git commit -m "chore(release): v${VERSION} [skip ci]"
121+
git push origin HEAD:main
122+
123+
- name: Get new HEAD of main after push
124+
id: head
125+
run: |
126+
git fetch origin main
127+
echo "sha=$(git rev-parse origin/main)" >> $GITHUB_OUTPUT
128+
129+
- name: Expose next_version for downstream jobs
130+
id: expose
131+
run: echo "next_version=${{ needs.check_commit.outputs.next_version }}" >> "$GITHUB_OUTPUT"
89132

90133
release:
91134
needs: ["prepare_release"]
135+
if: needs.prepare_release.result == 'success'
92136
uses: ./.github/workflows/workflow-release-drafter.yml
93137
with:
94138
version: ${{ needs.prepare_release.outputs.next_version }}
139+
target_sha: ${{ needs.prepare_release.outputs.head_sha }}
95140
secrets: inherit

.github/workflows/workflow-release-drafter.yml

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,24 @@ on:
77
inputs:
88
publish:
99
type: boolean
10-
description: Wether to publish Release note
10+
description: Whether to publish Release note
1111
required: false
1212
default: false
1313
version:
1414
required: true
1515
type: string
16+
target_sha:
17+
required: true
18+
type: string
19+
description: "Commit SHA to tag"
1620

1721
permissions:
1822
contents: read
1923

24+
concurrency:
25+
group: release-${{ inputs.version }}
26+
cancel-in-progress: false
27+
2028
jobs:
2129
update_release_draft:
2230
permissions:
@@ -28,11 +36,32 @@ jobs:
2836
uses: actions/checkout@v5
2937
with:
3038
fetch-depth: 2
39+
token: ${{ secrets.GH_INFRAHUB_BOT_TOKEN }}
3140

32-
- name: Tag new version
41+
- name: Ensure tag exists on the target commit
42+
env:
43+
VERSION: ${{ inputs.version }}
44+
TARGET_SHA: ${{ inputs.target_sha }}
3345
run: |
34-
git tag ${{ inputs.version }}
35-
git push --tags
46+
set -euo pipefail
47+
git fetch origin --tags
48+
# Ensure the target commit exists locally
49+
if ! git cat-file -e "${TARGET_SHA}^{commit}" >/dev/null 2>&1; then
50+
echo "::error::Target SHA ${TARGET_SHA} not found locally"
51+
exit 1
52+
fi
53+
if git rev-parse -q --verify "refs/tags/${VERSION}" >/dev/null; then
54+
existing_sha="$(git rev-list -n 1 "${VERSION}")"
55+
if [ "${existing_sha}" = "${TARGET_SHA}" ]; then
56+
echo "Tag ${VERSION} already points to ${TARGET_SHA} — OK"
57+
else
58+
echo "::error::Tag ${VERSION} exists on ${existing_sha}, refusing to move to ${TARGET_SHA}."
59+
exit 1
60+
fi
61+
else
62+
git tag -a "${VERSION}" "${TARGET_SHA}" -m "Release ${VERSION}"
63+
git push origin "refs/tags/${VERSION}"
64+
fi
3665
3766
- uses: release-drafter/release-drafter@v6
3867
with:

0 commit comments

Comments
 (0)