|
| 1 | +name: Release |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + push: |
| 5 | + branches: [ release ] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: ${{ github.workflow }} |
| 9 | + cancel-in-progress: false |
| 10 | + |
| 11 | +env: |
| 12 | + GH_TOKEN: ${{ secrets.ORB_CI_GH_TOKEN }} |
| 13 | + SEMANTIC_RELEASE_PACKAGE: ${{ github.repository }} |
| 14 | + PYTHON_RUNTIME_VERSION: "3.11" |
| 15 | + APP_NAME: diode-sdk-python |
| 16 | + PYTHON_PACKAGE_NAME: netboxlabs-diode-sdk |
| 17 | + |
| 18 | +jobs: |
| 19 | + get-next-version: |
| 20 | + name: Semantic release get next version |
| 21 | + runs-on: ubuntu-latest |
| 22 | + timeout-minutes: 5 |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + - uses: actions/setup-node@v4 |
| 26 | + with: |
| 27 | + node-version: "lts/*" |
| 28 | + - name: Write package.json |
| 29 | + uses: DamianReeves/write-file-action@master |
| 30 | + with: |
| 31 | + path: ./package.json |
| 32 | + write-mode: overwrite |
| 33 | + contents: | |
| 34 | + { |
| 35 | + "name": "${{ env.APP_NAME }}", |
| 36 | + "version": "1.0.0", |
| 37 | + "devDependencies": { |
| 38 | + "semantic-release-export-data": "^1.0.1", |
| 39 | + "@semantic-release/changelog": "^6.0.3" |
| 40 | + } |
| 41 | + } |
| 42 | + - name: Write .releaserc.json |
| 43 | + uses: DamianReeves/write-file-action@master |
| 44 | + with: |
| 45 | + path: ./.releaserc.json |
| 46 | + write-mode: overwrite |
| 47 | + contents: | |
| 48 | + { |
| 49 | + "branches": "release", |
| 50 | + "repositoryUrl": "https://github.com/netboxlabs/diode-sdk-python", |
| 51 | + "debug": "true", |
| 52 | + "tagFormat": "v${version}", |
| 53 | + "plugins": [ |
| 54 | + ["semantic-release-export-data"], |
| 55 | + ["@semantic-release/commit-analyzer", { |
| 56 | + "releaseRules": [ |
| 57 | + { "message": "*", "release": "patch"}, |
| 58 | + { "message": "fix*", "release": "patch" }, |
| 59 | + { "message": "feat*", "release": "minor" }, |
| 60 | + { "message": "perf*", "release": "major" } |
| 61 | + ] |
| 62 | + }], |
| 63 | + "@semantic-release/release-notes-generator", |
| 64 | + [ |
| 65 | + "@semantic-release/changelog", |
| 66 | + { |
| 67 | + "changelogFile": "CHANGELOG.md", |
| 68 | + "changelogTitle": "# Semantic Versioning Changelog" |
| 69 | + } |
| 70 | + ], |
| 71 | + [ |
| 72 | + "@semantic-release/github", |
| 73 | + { |
| 74 | + "assets": [ |
| 75 | + { |
| 76 | + "path": "release/**" |
| 77 | + } |
| 78 | + ] |
| 79 | + } |
| 80 | + ] |
| 81 | + ] |
| 82 | + } |
| 83 | + - name: setup semantic-release |
| 84 | + run: npm i |
| 85 | + - name: release dry-run |
| 86 | + env: |
| 87 | + SLACK_WEBHOOK: ${{ secrets.SLACK_SEMANTIC_RELEASE_WEBHOOK }} |
| 88 | + run: npx semantic-release --debug --dry-run |
| 89 | + id: get-next-version |
| 90 | + - name: Set short sha output |
| 91 | + id: short-sha |
| 92 | + run: echo "::set-output name=short-sha::${GITHUB_SHA::7}" |
| 93 | + - name: Set release version |
| 94 | + id: release-version |
| 95 | + run: | |
| 96 | + echo "::set-output name=release-version::`echo ${{ steps.get-next-version.outputs.new-release-version }} | sed 's/v//g'`" |
| 97 | + outputs: |
| 98 | + new-release-published: ${{ steps.get-next-version.outputs.new-release-published }} |
| 99 | + new-release-version: ${{ steps.release-version.outputs.release-version }} |
| 100 | + short-sha: ${{ steps.short-sha.outputs.short-sha }} |
| 101 | + |
| 102 | + confirm-version: |
| 103 | + name: Next version ${{ needs.get-next-version.outputs.new-release-version }} |
| 104 | + runs-on: ubuntu-latest |
| 105 | + timeout-minutes: 5 |
| 106 | + needs: get-next-version |
| 107 | + if: needs.get-next-version.outputs.new-release-published == 'true' |
| 108 | + steps: |
| 109 | + - uses: actions/checkout@v4 |
| 110 | + - run: echo "The new release version is ${{ needs.get-next-version.outputs.new-release-version }} commit ${{ needs.get-next-version.outputs.short-sha }}" |
| 111 | + |
| 112 | + build: |
| 113 | + name: Build |
| 114 | + needs: [ get-next-version ] |
| 115 | + runs-on: ubuntu-latest |
| 116 | + timeout-minutes: 5 |
| 117 | + permissions: |
| 118 | + id-token: write |
| 119 | + contents: read |
| 120 | + env: |
| 121 | + BUILD_VERSION: ${{ needs.get-next-version.outputs.new-release-version }} |
| 122 | + BUILD_TRACK: release |
| 123 | + BUILD_COMMIT: ${{ needs.get-next-version.outputs.short-sha }} |
| 124 | + steps: |
| 125 | + - uses: actions/checkout@v3 |
| 126 | + - uses: actions/setup-python@v5 |
| 127 | + with: |
| 128 | + python-version: ${{ env.PYTHON_RUNTIME_VERSION }} |
| 129 | + - name: Insert version variables into Python |
| 130 | + run: | |
| 131 | + sed -i "s/__commit_hash__ = .*/__commit_hash__ = \"${BUILD_COMMIT}\"/" netboxlabs/diode/sdk/version.py |
| 132 | + sed -i "s/__track__ = .*/__track__ = \"${BUILD_TRACK}\"/" netboxlabs/diode/sdk/version.py |
| 133 | + sed -i "s/__version__ = .*/__version__ = \"${BUILD_VERSION}\"/" netboxlabs/diode/sdk/version.py |
| 134 | + - name: Display contents of version.py |
| 135 | + run: cat netboxlabs/diode/sdk/version.py |
| 136 | + - name: Build sdist package |
| 137 | + run: | |
| 138 | + pip install toml-cli |
| 139 | + toml set --toml-path pyproject.toml project.version ${{ env.BUILD_VERSION }} |
| 140 | + cat pyproject.toml | grep version |
| 141 | + python3 -m pip install --upgrade build |
| 142 | + python3 -m build --sdist --outdir dist/ |
| 143 | + - name: Upload artifact |
| 144 | + uses: actions/upload-artifact@v4 |
| 145 | + with: |
| 146 | + name: ${{ env.PYTHON_PACKAGE_NAME }}-${{ env.BUILD_VERSION }}.tar.gz |
| 147 | + path: ./dist/${{ env.PYTHON_PACKAGE_NAME }}-${{ env.BUILD_VERSION }}.tar.gz |
| 148 | + retention-days: 30 |
| 149 | + if-no-files-found: error |
| 150 | + - name: Publish release distributions to PyPI |
| 151 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 152 | + with: |
| 153 | + packages-dir: ./dist |
| 154 | + |
| 155 | + semantic-release: |
| 156 | + name: Semantic release |
| 157 | + needs: [ build ] |
| 158 | + runs-on: ubuntu-latest |
| 159 | + timeout-minutes: 5 |
| 160 | + steps: |
| 161 | + - uses: actions/checkout@v4 |
| 162 | + - uses: actions/setup-node@v4 |
| 163 | + with: |
| 164 | + node-version: "21.4.0" |
| 165 | + - name: setup semantic-release |
| 166 | + run: npm i |
| 167 | + - name: Release |
| 168 | + env: |
| 169 | + SLACK_WEBHOOK: ${{ secrets.SLACK_OBSERVABILITY_RELEASE_WEBHOOK }} |
| 170 | + run: npx semantic-release --debug |
0 commit comments