|
| 1 | +name: Publish to PyPi |
| 2 | + |
| 3 | +# RELEASE PROCESS |
| 4 | +# |
| 5 | +# === Manual activities === |
| 6 | +# |
| 7 | +# 1. Edit the current draft release notes |
| 8 | +# 2. If not already set, use `v<new version>` as a tag, e.g., v1.26.4, and select develop as target branch |
| 9 | +# |
| 10 | +# === Automated activities === |
| 11 | +# |
| 12 | +# 1. Extract release notes tag that was published |
| 13 | +# 2. Run tests, linting, security and complexity base line |
| 14 | +# 3. Bump package version and generate latest Changelog |
| 15 | +# 4. Publish package to PyPi test and prod repository |
| 16 | +# 5. Kick off SAR App pipeline to publish latest version with minimal and extra dependencies |
| 17 | +# 6. Builds and publish latest changelog from tip of the branch |
| 18 | +# 7. Builds a new user guide and API docs with release version; update /latest pointing to newly released version |
| 19 | +# 8. Close all issues labeled "pending-release" and notify customers about the release |
| 20 | + |
| 21 | +# See MAINTAINERS.md "Releasing a new version" for release mechanisms |
| 22 | + |
| 23 | +env: |
| 24 | + BRANCH: develop |
| 25 | + |
| 26 | +on: |
| 27 | + release: |
| 28 | + types: [published] |
| 29 | + workflow_dispatch: |
| 30 | + inputs: |
| 31 | + version_to_publish: |
| 32 | + description: "Version to be released in PyPi, Docs, and Lambda Layer, e.g. v1.26.4" |
| 33 | + default: v1.26.4 |
| 34 | + required: true |
| 35 | + skip_pypi: |
| 36 | + description: "Skip publishing to PyPi as it can't publish more than once. Useful for semi-failed releases" |
| 37 | + default: false |
| 38 | + type: boolean |
| 39 | + required: false |
| 40 | + skip_code_quality: |
| 41 | + description: "Skip tests, linting, and baseline. Only use if release fail for reasons beyond our control and you need a quick release." |
| 42 | + default: false |
| 43 | + type: boolean |
| 44 | + required: false |
| 45 | + |
| 46 | +jobs: |
| 47 | + release: |
| 48 | + environment: release |
| 49 | + runs-on: ubuntu-latest |
| 50 | + permissions: |
| 51 | + id-token: write |
| 52 | + contents: read |
| 53 | + outputs: |
| 54 | + RELEASE_VERSION: ${{ steps.release_version.outputs.RELEASE_VERSION }} |
| 55 | + env: |
| 56 | + RELEASE_TAG_VERSION: ${{ github.event.release.tag_name || inputs.version_to_publish }} |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v3 |
| 59 | + with: |
| 60 | + fetch-depth: 0 |
| 61 | + - name: Install poetry |
| 62 | + run: pipx install poetry |
| 63 | + - name: Set up Python |
| 64 | + uses: actions/setup-python@v4 |
| 65 | + with: |
| 66 | + python-version: "3.8" |
| 67 | + cache: "poetry" |
| 68 | + - name: Set release notes tag |
| 69 | + id: release_version |
| 70 | + # transform tag format `v<version` to `<version` |
| 71 | + run: | |
| 72 | + RELEASE_VERSION="${RELEASE_TAG_VERSION:1}" |
| 73 | + echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "$GITHUB_ENV" |
| 74 | + echo "::set-output name=RELEASE_VERSION::${RELEASE_VERSION}" |
| 75 | + - name: Install dependencies |
| 76 | + run: make dev |
| 77 | + - name: Run all tests, linting and baselines |
| 78 | + if: ${{ !inputs.skip_code_quality }} |
| 79 | + run: make pr |
| 80 | + - name: Bump package version |
| 81 | + run: poetry version "${RELEASE_VERSION}" |
| 82 | + - name: Build python package and wheel |
| 83 | + if: ${{ !inputs.skip_pypi }} |
| 84 | + run: poetry build |
| 85 | + - name: Upload to PyPi test |
| 86 | + if: ${{ !inputs.skip_pypi }} |
| 87 | + run: make release-test |
| 88 | + env: |
| 89 | + PYPI_USERNAME: __token__ |
| 90 | + PYPI_TEST_TOKEN: ${{ secrets.PYPI_TEST_TOKEN }} |
| 91 | + - name: Upload to PyPi prod |
| 92 | + if: ${{ !inputs.skip_pypi }} |
| 93 | + run: make release-prod |
| 94 | + env: |
| 95 | + PYPI_USERNAME: __token__ |
| 96 | + PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} |
| 97 | + - name: aws credentials |
| 98 | + uses: aws-actions/configure-aws-credentials@v1 |
| 99 | + with: |
| 100 | + aws-region: eu-west-1 |
| 101 | + role-to-assume: ${{ secrets.AWS_SAR_ROLE_ARN }} |
| 102 | + - name: publish lambda layer in SAR by triggering the internal codepipeline |
| 103 | + run: | |
| 104 | + aws ssm put-parameter --name "powertools-python-release-version" --value "$RELEASE_VERSION" --overwrite |
| 105 | + aws codepipeline start-pipeline-execution --name ${{ secrets.AWS_SAR_PIPELINE_NAME }} |
| 106 | +
|
| 107 | + changelog: |
| 108 | + needs: release |
| 109 | + permissions: |
| 110 | + contents: write |
| 111 | + uses: ./.github/workflows/reusable_publish_changelog.yml |
| 112 | + |
| 113 | + docs: |
| 114 | + needs: [release, changelog] |
| 115 | + permissions: |
| 116 | + contents: write |
| 117 | + pages: write |
| 118 | + uses: ./.github/workflows/reusable_publish_docs.yml |
| 119 | + with: |
| 120 | + version: ${{ needs.release.outputs.RELEASE_VERSION }} |
| 121 | + alias: latest |
| 122 | + detached_mode: true |
| 123 | + |
| 124 | + post_release: |
| 125 | + needs: release |
| 126 | + permissions: |
| 127 | + contents: read |
| 128 | + issues: write |
| 129 | + discussions: write |
| 130 | + pull-requests: write |
| 131 | + runs-on: ubuntu-latest |
| 132 | + env: |
| 133 | + RELEASE_VERSION: ${{ needs.release.outputs.RELEASE_VERSION }} |
| 134 | + steps: |
| 135 | + - uses: actions/checkout@v3 |
| 136 | + - name: Close issues related to this release |
| 137 | + uses: actions/github-script@v6 |
| 138 | + with: |
| 139 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 140 | + script: | |
| 141 | + const post_release = require('.github/scripts/post_release.js') |
| 142 | + await post_release({github, context, core}) |
0 commit comments