|
| 1 | +name: Create Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_notes: |
| 7 | + description: 'Release notes' |
| 8 | + type: string |
| 9 | + required: false |
| 10 | + default: '' |
| 11 | + upload_to_pypi: |
| 12 | + description: 'Upload the release to PyPI' |
| 13 | + type: boolean |
| 14 | + required: false |
| 15 | + default: true |
| 16 | + |
| 17 | +permissions: |
| 18 | + actions: write |
| 19 | + contents: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + name: Build |
| 24 | + runs-on: ubuntu-latest |
| 25 | + outputs: |
| 26 | + version: ${{ steps.get-version.outputs.VERSION }} |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Checkout project |
| 30 | + uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Setup Python |
| 33 | + uses: actions/setup-python@v5 |
| 34 | + with: |
| 35 | + python-version: "3.11" |
| 36 | + |
| 37 | + - name: Install Poetry |
| 38 | + uses: abatilo/actions-poetry@v4 |
| 39 | + with: |
| 40 | + poetry-version: "1.8.5" |
| 41 | + |
| 42 | + - name: Setup a local virtual environment |
| 43 | + run: | |
| 44 | + poetry config virtualenvs.create true --local |
| 45 | + poetry config virtualenvs.in-project true --local |
| 46 | +
|
| 47 | + - name: Define a cache for the virtual environment based on the dependencies lock file |
| 48 | + uses: actions/cache@v4 |
| 49 | + with: |
| 50 | + path: ./.venv |
| 51 | + key: venv-${{ hashFiles('poetry.lock') }} |
| 52 | + |
| 53 | + - name: Build |
| 54 | + run: | |
| 55 | + poetry install |
| 56 | + poetry build |
| 57 | +
|
| 58 | + - name: Get package version to create a new tag and release |
| 59 | + id: get-version |
| 60 | + run: echo "VERSION=$(poetry version --short)" >> $GITHUB_OUTPUT |
| 61 | + |
| 62 | + - name: Upload build artifacts |
| 63 | + uses: actions/upload-artifact@v4 |
| 64 | + with: |
| 65 | + name: csaps-packages |
| 66 | + path: dist/* |
| 67 | + overwrite: true |
| 68 | + |
| 69 | + publish: |
| 70 | + name: Publish |
| 71 | + needs: [ build ] |
| 72 | + runs-on: ubuntu-latest |
| 73 | + environment: |
| 74 | + name: release |
| 75 | + url: https://pypi.org/project/csaps |
| 76 | + permissions: |
| 77 | + id-token: write |
| 78 | + env: |
| 79 | + TAG_NAME: v${{ needs.build.outputs.version }} |
| 80 | + |
| 81 | + steps: |
| 82 | + - uses: actions/download-artifact@v4 |
| 83 | + with: |
| 84 | + name: csaps-packages |
| 85 | + path: dist |
| 86 | + |
| 87 | + - name: Check tag ${{ TAG_NAME }} |
| 88 | + uses: mukunku/tag-exists-action@v1.6.0 |
| 89 | + id: check-tag |
| 90 | + with: |
| 91 | + tag: ${{ TAG_NAME }} |
| 92 | + |
| 93 | + - name: Create tag ${{ TAG_NAME }} |
| 94 | + if: ${{ steps.check-tag.outputs.exists == 'false' }} |
| 95 | + uses: actions/github-script@v7 |
| 96 | + with: |
| 97 | + script: | |
| 98 | + github.rest.git.createRef({ |
| 99 | + owner: context.repo.owner, |
| 100 | + repo: context.repo.repo, |
| 101 | + ref: 'refs/tags/${{ TAG_NAME }}', |
| 102 | + sha: context.sha |
| 103 | + }) |
| 104 | +
|
| 105 | + - name: Create release ${{ TAG_NAME }} |
| 106 | + uses: softprops/action-gh-release@v2 |
| 107 | + with: |
| 108 | + name: ${{ TAG_NAME }} |
| 109 | + tag_name: ${{ TAG_NAME }} |
| 110 | + files: dist/* |
| 111 | + body: inputs.release_notes |
| 112 | + |
| 113 | + - name: Upload to PyPI |
| 114 | + if: ${{ inputs.upload_to_pypi }} |
| 115 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments