|
1 | | -name: Build Release Distribution |
2 | | - |
3 | | -on: |
4 | | - push: |
5 | | - tags: |
6 | | - # below is same as ^\d{4}\.\d{2}\.\d{2}$ seems workflows use simpler regex |
7 | | - - '[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9].[0-9]+' |
8 | | - |
9 | | -jobs: |
10 | | - build-and-release: |
11 | | - name: Build and Release |
12 | | - runs-on: ubuntu-latest |
13 | | - |
14 | | - steps: |
15 | | - - name: Checkout Code |
16 | | - uses: actions/checkout@v4 |
17 | | - with: |
18 | | - fetch-depth: 0 |
19 | | - |
20 | | - - name: Checkout release |
21 | | - run: | |
22 | | - git fetch origin release |
23 | | - git checkout release |
24 | | -
|
25 | | - - name: Determine Version |
26 | | - id: get-version |
27 | | - env: |
28 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
29 | | - run: | |
30 | | - VERSION="${GITHUB_REF#refs/tags/}" |
31 | | - echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
32 | | -
|
33 | | - - name: Determine If Tag Is From Release |
34 | | - id: is-release |
35 | | - env: |
36 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
37 | | - run: | |
38 | | - TAG_COMMIT=$(git rev-parse ${{ github.ref }}) |
39 | | - BRANCHES=$(git branch -r --contains "$TAG_COMMIT") |
40 | | -
|
41 | | - if echo "$BRANCHES" | grep -q 'origin/release'; then |
42 | | - echo "should_continue=true" >> "$GITHUB_OUTPUT" |
43 | | - else |
44 | | - echo "Exiting Workflow: Tag is not from release branch" |
45 | | - echo "IF intending to create a release from tag follow steps under 'Creating A Release' in the README file" |
46 | | - echo "should_continue=false" >> "$GITHUB_OUTPUT" |
47 | | - fi |
48 | | -
|
49 | | - - name: Setup Python |
50 | | - if: steps.is-release.outputs.should_continue == 'true' |
51 | | - uses: actions/setup-python@v5 |
52 | | - with: |
53 | | - python-version: '3.10' |
54 | | - |
55 | | - - name: Install Poetry |
56 | | - if: steps.is-release.outputs.should_continue == 'true' |
57 | | - run: | |
58 | | - curl -sSL https://install.python-poetry.org | python3 - |
59 | | - poetry --version |
60 | | -
|
61 | | - - name: Install Dependencies |
62 | | - if: steps.is-release.outputs.should_continue == 'true' |
63 | | - run: | |
64 | | - poetry install --no-root --with dev |
65 | | -
|
66 | | - - name: Build Wheel |
67 | | - if: steps.is-release.outputs.should_continue == 'true' |
68 | | - run: | |
69 | | - poetry build |
70 | | -
|
71 | | - - name: Create Release |
72 | | - if: steps.is-release.outputs.should_continue == 'true' |
73 | | - env: |
74 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
75 | | - run: | |
76 | | - gh release create ${{ github.ref }} dist/* --generate-notes --latest |
77 | | -
|
78 | | - - name: Update pyproject.toml Version |
79 | | - if: steps.is-release.outputs.should_continue == 'true' |
80 | | - env: |
81 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
82 | | - run: | |
83 | | - VERSION=${{ steps.get-version.outputs.version }} |
84 | | -
|
85 | | - sed -i.bak -E "s/^version\s*=\s*\"[^\"]+\"/version = \"${VERSION}\"/" pyproject.toml |
86 | | -
|
87 | | - - name: Update Change Log |
88 | | - if: steps.is-release.outputs.should_continue == 'true' |
89 | | - env: |
90 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
91 | | - run: | |
92 | | - VERSION=${{ steps.get-version.outputs.version }} |
93 | | - REPO_URL="https://github.com/${{ github.repository }}" |
94 | | - RELEASE_URL="$REPO_URL/releases/tag/$VERSION" |
95 | | -
|
96 | | - awk -v tag="## [$VERSION]" -v url="$RELEASE_URL" ' |
97 | | - !done && /---/ { |
98 | | - print $0 |
99 | | - print "" |
100 | | - print tag |
101 | | - print url |
102 | | - done = 1 |
103 | | - next |
104 | | - } |
105 | | - { print $0 } |
106 | | - ' changelog.md > temp.md && mv temp.md changelog.md |
107 | | -
|
108 | | - - name: Commit Change Log and pyproject.toml Updates |
109 | | - if: steps.is-release.outputs.should_continue == 'true' |
110 | | - env: |
111 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
112 | | - run: | |
113 | | - VERSION=${{ steps.get-version.outputs.version }} |
114 | | -
|
115 | | - git config user.name "github-actions" |
116 | | - git config user.email "github-actions@users.noreply.github.com" |
117 | | - git add pyproject.toml changelog.md |
118 | | - git commit -m "Update Version to ${{ steps.get-version.outputs.version }}" |
119 | | - git push origin release |
| 1 | +name: Build Release Distribution |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + # below is same as ^\d{4}\.\d{2}\.\d{2}$ seems workflows use simpler regex |
| 7 | + - '[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9].[0-9]+' |
| 8 | + |
| 9 | +jobs: |
| 10 | + build-and-release: |
| 11 | + name: Build and Release |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout Code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Checkout release |
| 21 | + run: | |
| 22 | + git fetch origin release |
| 23 | + git checkout release |
| 24 | +
|
| 25 | + - name: Determine Version |
| 26 | + id: get-version |
| 27 | + env: |
| 28 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + run: | |
| 30 | + VERSION="${GITHUB_REF#refs/tags/}" |
| 31 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 32 | +
|
| 33 | + - name: Determine If Tag Is From Release |
| 34 | + id: is-release |
| 35 | + env: |
| 36 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + run: | |
| 38 | + TAG_COMMIT=$(git rev-parse ${{ github.ref }}) |
| 39 | + BRANCHES=$(git branch -r --contains "$TAG_COMMIT") |
| 40 | +
|
| 41 | + if echo "$BRANCHES" | grep -q 'origin/release'; then |
| 42 | + echo "should_continue=true" >> "$GITHUB_OUTPUT" |
| 43 | + else |
| 44 | + echo "Exiting Workflow: Tag is not from release branch" |
| 45 | + echo "IF intending to create a release from tag follow steps under 'Creating A Release' in the README file" |
| 46 | + echo "should_continue=false" >> "$GITHUB_OUTPUT" |
| 47 | + fi |
| 48 | +
|
| 49 | + - name: Setup Python |
| 50 | + if: steps.is-release.outputs.should_continue == 'true' |
| 51 | + uses: actions/setup-python@v5 |
| 52 | + with: |
| 53 | + python-version: '3.10' |
| 54 | + |
| 55 | + - name: Install Poetry |
| 56 | + if: steps.is-release.outputs.should_continue == 'true' |
| 57 | + run: | |
| 58 | + curl -sSL https://install.python-poetry.org | python3 - |
| 59 | + poetry --version |
| 60 | +
|
| 61 | + - name: Install Dependencies |
| 62 | + if: steps.is-release.outputs.should_continue == 'true' |
| 63 | + run: | |
| 64 | + poetry install --no-root --with dev |
| 65 | +
|
| 66 | + - name: Build Wheel |
| 67 | + if: steps.is-release.outputs.should_continue == 'true' |
| 68 | + run: | |
| 69 | + poetry build |
| 70 | +
|
| 71 | + - name: Create Release |
| 72 | + if: steps.is-release.outputs.should_continue == 'true' |
| 73 | + env: |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + run: | |
| 76 | + gh release create ${{ github.ref }} dist/* --generate-notes --latest |
| 77 | +
|
| 78 | + - name: Update pyproject.toml Version |
| 79 | + if: steps.is-release.outputs.should_continue == 'true' |
| 80 | + env: |
| 81 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + run: | |
| 83 | + VERSION=${{ steps.get-version.outputs.version }} |
| 84 | +
|
| 85 | + sed -i.bak -E "s/^version\s*=\s*\"[^\"]+\"/version = \"${VERSION}\"/" pyproject.toml |
| 86 | +
|
| 87 | + - name: Update Change Log |
| 88 | + if: steps.is-release.outputs.should_continue == 'true' |
| 89 | + env: |
| 90 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + run: | |
| 92 | + VERSION=${{ steps.get-version.outputs.version }} |
| 93 | + REPO_URL="https://github.com/${{ github.repository }}" |
| 94 | + RELEASE_URL="$REPO_URL/releases/tag/$VERSION" |
| 95 | +
|
| 96 | + awk -v tag="## [$VERSION]" -v url="$RELEASE_URL" ' |
| 97 | + !done && /---/ { |
| 98 | + print $0 |
| 99 | + print "" |
| 100 | + print tag |
| 101 | + print url |
| 102 | + done = 1 |
| 103 | + next |
| 104 | + } |
| 105 | + { print $0 } |
| 106 | + ' changelog.md > temp.md && mv temp.md changelog.md |
| 107 | +
|
| 108 | + - name: Commit Change Log and pyproject.toml Updates |
| 109 | + if: steps.is-release.outputs.should_continue == 'true' |
| 110 | + env: |
| 111 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + run: | |
| 113 | + VERSION=${{ steps.get-version.outputs.version }} |
| 114 | +
|
| 115 | + git config user.name "github-actions" |
| 116 | + git config user.email "github-actions@users.noreply.github.com" |
| 117 | + git add pyproject.toml changelog.md |
| 118 | + git commit -m "Update Version to ${{ steps.get-version.outputs.version }}" |
| 119 | + git push origin release |
0 commit comments