|
1 | 1 | --- |
2 | 2 | # yamllint disable rule:truthy |
3 | | -name: "Push on main/stable" |
| 3 | +name: "Push on main" |
4 | 4 |
|
5 | 5 | on: |
6 | 6 | push: |
|
10 | 10 | paths-ignore: |
11 | 11 | - 'docs/**' |
12 | 12 |
|
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + |
13 | 16 | jobs: |
14 | 17 | check_commit: |
15 | 18 | runs-on: ubuntu-latest |
16 | 19 | 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 }} |
18 | 24 | steps: |
19 | 25 | - uses: actions/checkout@v5 |
20 | 26 | 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 |
23 | 32 | 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" |
31 | 66 | fi |
32 | 67 |
|
| 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 | +
|
33 | 77 | prepare_release: |
34 | 78 | needs: check_commit |
35 | 79 | if: needs.check_commit.outputs.skip == 'false' |
36 | 80 | runs-on: ubuntu-22.04 |
37 | 81 | outputs: |
38 | | - next_version: ${{ steps.version.outputs.next-version }} |
| 82 | + head_sha: ${{ steps.head.outputs.sha }} |
| 83 | + next_version: ${{ steps.expose.outputs.next_version }} |
39 | 84 | 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 |
42 | 92 | with: |
43 | 93 | python-version: "3.11" |
44 | 94 |
|
45 | | - - name: "Install Poetry" |
46 | | - uses: "snok/install-poetry@v1" |
| 95 | + - name: Install Poetry |
| 96 | + uses: snok/install-poetry@v1 |
47 | 97 | with: |
48 | 98 | version: 2.1.3 |
49 | 99 | virtualenvs-create: true |
50 | 100 | virtualenvs-in-project: true |
51 | 101 | installer-parallel: true |
52 | 102 |
|
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 | | - |
70 | 103 | - name: Update pyproject.toml versions |
| 104 | + env: |
| 105 | + VERSION: ${{ needs.check_commit.outputs.next_version }} |
71 | 106 | run: | |
72 | | - VERSION=${{ steps.version.outputs.next-version }} |
73 | 107 | echo "Updating to version $VERSION" |
74 | | - poetry version $VERSION # directly use the VERSION |
| 108 | + poetry version "$VERSION" |
75 | 109 |
|
76 | 110 | - name: Update lock file |
77 | 111 | run: poetry lock |
78 | 112 |
|
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" |
89 | 132 |
|
90 | 133 | release: |
91 | 134 | needs: ["prepare_release"] |
| 135 | + if: needs.prepare_release.result == 'success' |
92 | 136 | uses: ./.github/workflows/workflow-release-drafter.yml |
93 | 137 | with: |
94 | 138 | version: ${{ needs.prepare_release.outputs.next_version }} |
| 139 | + target_sha: ${{ needs.prepare_release.outputs.head_sha }} |
95 | 140 | secrets: inherit |
0 commit comments