|
1 | 1 | --- |
2 | | -name: Deploy Salt Extension Python Package |
| 2 | +name: Release Salt Extension Python Package |
3 | 3 |
|
4 | 4 | on: |
5 | | - workflow_call: |
6 | | - inputs: |
7 | | - test: |
8 | | - type: boolean |
9 | | - required: false |
10 | | - default: true |
11 | | - version: |
12 | | - type: string |
13 | | - required: true |
14 | | - secrets: |
15 | | - PYPI_API_TOKEN: |
16 | | - required: false |
17 | | - TEST_PYPI_API_TOKEN: |
18 | | - required: false |
| 5 | + workflow_run: |
| 6 | + types: |
| 7 | + - completed |
| 8 | + workflows: |
| 9 | + - Auto PR Releases |
| 10 | + - Tagged Releases |
19 | 11 |
|
20 | 12 | jobs: |
21 | | - build: |
22 | | - name: Publish Python Package to ${{ ! inputs.test && 'PyPI' || 'Test PyPI' }} |
| 13 | + get_version: |
| 14 | + name: Get package version |
23 | 15 | runs-on: ubuntu-24.04 |
| 16 | + if: github.event.workflow_run.conclusion == 'success' |
| 17 | + permissions: |
| 18 | + actions: read |
| 19 | + outputs: |
| 20 | + version: ${{ steps.extract-version.outputs.version }} |
24 | 21 |
|
25 | 22 | steps: |
| 23 | + - name: Download expected version |
| 24 | + uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 25 | + with: |
| 26 | + name: version.txt |
| 27 | + path: ${{ runner.temp }} |
| 28 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + run-id: ${{ github.event.workflow_run.id }} |
| 30 | + |
26 | 31 | - name: Download Python Package Artifacts |
| 32 | +<<<<<<< before updating |
27 | 33 | uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 |
| 34 | +======= |
| 35 | + uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 36 | +>>>>>>> after updating |
28 | 37 | with: |
29 | | - name: salt-extension-${{ inputs.version }}-packages |
| 38 | + name: salt-extension-packages |
30 | 39 | path: dist |
| 40 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + run-id: ${{ github.event.workflow_run.id }} |
| 42 | + |
| 43 | + - name: Extract and verify package version |
| 44 | + id: extract-version |
| 45 | + run: |- |
| 46 | + wheel_file="$(find dist -name '*.whl' | head -n 1)" |
| 47 | + test -n "$wheel_file" || exit 1 |
| 48 | + unzip "$wheel_file" -d "$RUNNER_TEMP/extract" |
| 49 | + dist_info="$(find "$RUNNER_TEMP/extract" -type d -name '*.dist-info' | head -n 1)" |
| 50 | + test -n "$dist_info" || exit 1 |
| 51 | + package_version="$(sed -n 's/^Version:\s*\(\S*\)$/\1/p' "$dist_info/METADATA")" |
| 52 | + test -n "$package_version" || exit 1 |
| 53 | + expected_version="$(cat "$RUNNER_TEMP/version.txt" | head -n 1)" |
| 54 | + echo "Detected package version: $package_version" |
| 55 | + echo "Expected version: $expected_version" |
| 56 | + test "$package_version" = "$expected_version" || exit 1 |
| 57 | + echo "version=$expected_version" >> "$GITHUB_OUTPUT" |
| 58 | +
|
| 59 | + test_release: |
| 60 | + name: Publish Python Package to Test PyPI |
| 61 | + runs-on: ubuntu-24.04 |
| 62 | + needs: |
| 63 | + - get_version |
| 64 | + permissions: |
| 65 | + actions: read |
| 66 | + id-token: write |
| 67 | + |
| 68 | + steps: |
| 69 | + - name: Download Python Package Artifacts |
| 70 | + uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 71 | + with: |
| 72 | + name: salt-extension-packages |
| 73 | + path: dist |
| 74 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + run-id: ${{ github.event.workflow_run.id }} |
31 | 76 |
|
32 | 77 | - name: Publish distribution to Test PyPI |
33 | | - uses: pypa/gh-action-pypi-publish@1bb664cc2ddedbbfdde43d4ac135d5836b7bf40f # v1.11.0 |
34 | | - if: ${{ inputs.test }} |
| 78 | + uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 |
35 | 79 | with: |
36 | | - attestations: false |
| 80 | + attestations: ${{ secrets.TEST_PYPI_API_TOKEN == '' }} |
37 | 81 | password: ${{ secrets.TEST_PYPI_API_TOKEN }} |
38 | 82 | repository-url: https://test.pypi.org/legacy/ |
| 83 | + verbose: ${{ runner.debug == '1' }} |
| 84 | + |
| 85 | + pypi_release: |
| 86 | + name: Publish Python Package to PyPI |
| 87 | + runs-on: ubuntu-24.04 |
| 88 | + needs: |
| 89 | + - test_release |
| 90 | + permissions: |
| 91 | + actions: read |
| 92 | + id-token: write |
| 93 | + environment: |
| 94 | + name: release |
| 95 | + url: https://pypi.org/p/saltext.nebula |
| 96 | + |
| 97 | + steps: |
| 98 | + - name: Download Python Package Artifacts |
| 99 | + uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 100 | + with: |
| 101 | + name: salt-extension-packages |
| 102 | + path: dist |
| 103 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + run-id: ${{ github.event.workflow_run.id }} |
| 105 | + |
| 106 | + - name: Publish distribution to PyPI |
| 107 | + uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 |
| 108 | + with: |
| 109 | + attestations: ${{ secrets.PYPI_API_TOKEN == '' }} |
| 110 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 111 | + verbose: ${{ runner.debug == '1' }} |
| 112 | + |
| 113 | + docs_release: |
| 114 | + name: Deploy Docs |
| 115 | + uses: ./.github/workflows/deploy-docs-action.yml |
| 116 | + needs: |
| 117 | + - pypi_release |
| 118 | + - get_version |
| 119 | + permissions: |
| 120 | + actions: read |
| 121 | + pages: write |
| 122 | + id-token: write |
| 123 | + |
| 124 | + gh_release: |
| 125 | + name: Create GitHub release |
| 126 | + runs-on: ubuntu-24.04 |
| 127 | + needs: |
| 128 | + - pypi_release |
| 129 | + - get_version |
| 130 | + permissions: |
| 131 | + actions: read |
| 132 | + contents: write |
| 133 | + |
| 134 | + steps: |
| 135 | + - name: Download Python Package Artifacts |
| 136 | + uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 137 | + with: |
| 138 | + name: salt-extension-packages |
| 139 | + path: dist |
| 140 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 141 | + run-id: ${{ github.event.workflow_run.id }} |
39 | 142 |
|
40 | 143 | - name: Create GitHub Release |
41 | | - if: ${{ !inputs.test }} |
42 | 144 | env: |
43 | 145 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 146 | + VERSION: ${{ needs.get_version.outputs.version }} |
44 | 147 | run: | |
45 | | - gh release create "v${{ inputs.version }}" \ |
| 148 | + gh release create "v${{ needs.get_version.outputs.version }}" \ |
46 | 149 | --repo="$GITHUB_REPOSITORY" \ |
47 | | - --title="${GITHUB_REPOSITORY#*/} ${{ inputs.version }}" \ |
| 150 | + --title="${GITHUB_REPOSITORY#*/} $VERSION" \ |
48 | 151 | --generate-notes \ |
49 | 152 | dist/* |
50 | | -
|
51 | | - - name: Publish distribution to PyPI |
52 | | - uses: pypa/gh-action-pypi-publish@1bb664cc2ddedbbfdde43d4ac135d5836b7bf40f # v1.11.0 |
53 | | - if: ${{ !inputs.test }} |
54 | | - with: |
55 | | - # Attestations are only submitted when using Trusted Publishing, |
56 | | - # which is triggered by secrets.PYPI_API_TOKEN not being set. |
57 | | - # They don't work with reusable workflows at the moment. |
58 | | - # It's related to https://github.com/pypi/warehouse/issues/11096 |
59 | | - attestations: false |
60 | | - password: ${{ secrets.PYPI_API_TOKEN }} |
|
0 commit comments