|
| 1 | +name: Publish |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + version_type: |
| 6 | + type: choice |
| 7 | + description: Version type |
| 8 | + default: minor |
| 9 | + options: |
| 10 | + - major |
| 11 | + - minor |
| 12 | + - patch |
| 13 | +jobs: |
| 14 | + publish: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v3 |
| 18 | + - name: Setup git repo |
| 19 | + run: | |
| 20 | + git config user.name $GITHUB_ACTOR |
| 21 | + git config user.email gh-actions-${GITHUB_ACTOR}@github.com |
| 22 | + git remote add gh-origin https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v4 |
| 25 | + with: |
| 26 | + python-version: 3.12 |
| 27 | + - name: Install dependencies |
| 28 | + run: | |
| 29 | + pip install poetry |
| 30 | + poetry install |
| 31 | + - name: Bump Version |
| 32 | + id: bump_version |
| 33 | + run: | |
| 34 | + NEW_VERSION=$(python scripts/update_version.py ${{ github.event.inputs.version_type }}) |
| 35 | + echo "NEW_VERSION=$NEW_VERSION" |
| 36 | + echo "new_version=$(echo $NEW_VERSION)" >> $GITHUB_OUTPUT |
| 37 | + - name: Generate with new version |
| 38 | + run: ./scripts/generate.sh |
| 39 | + - name: Build |
| 40 | + run: poetry build |
| 41 | + - name: Commit and push changes |
| 42 | + run: | |
| 43 | + git add ynab/configuration.py ynab/api_client.py ynab/__init__.py pyproject.toml openapi-generator-config.yaml && git diff-index --quiet HEAD || git commit -m 'Bumping version for ${{ steps.bump_version.outputs.new_version }}' |
| 44 | + git push gh-origin HEAD:main |
| 45 | + - name: Publish to PyPI |
| 46 | + env: |
| 47 | + POETRY_PYPI_TOKEN_PYPI: ${{ secrets.POETRY_PYPI_TOKEN_PYPI }} |
| 48 | + run: poetry publish |
| 49 | + - name: Create a Release |
| 50 | + id: create-release |
| 51 | + uses: softprops/action-gh-release@v1 |
| 52 | + with: |
| 53 | + tag_name: ${{ steps.bump_version.outputs.new_version }} |
| 54 | + generate_release_notes: true |
| 55 | + - name: Comment on PRs with link to release they are included in |
| 56 | + uses: actions/github-script@v6 |
| 57 | + env: |
| 58 | + RELEASE_ID: ${{ steps.create-release.outputs.id }} |
| 59 | + with: |
| 60 | + script: | |
| 61 | + const releaseId = process.env.RELEASE_ID; |
| 62 | + console.log(`Fetching release_id: ${releaseId} ...`); |
| 63 | + const getReleaseResponse = await github.rest.repos.getRelease({ |
| 64 | + release_id: process.env.RELEASE_ID, |
| 65 | + owner: context.repo.owner, |
| 66 | + repo: context.repo.repo |
| 67 | + }); |
| 68 | + const release = getReleaseResponse.data; |
| 69 | +
|
| 70 | + const prNumbersInRelease = new Set(Array.from(release.body.matchAll(/\/pull\/(\d+)/g)).map(p=>p[1])); |
| 71 | +
|
| 72 | + for(let prNumber of prNumbersInRelease) { |
| 73 | + console.log(`Adding comment on PR #${prNumber} ...`); |
| 74 | + await github.rest.issues.createComment({ |
| 75 | + issue_number: prNumber, |
| 76 | + owner: context.repo.owner, |
| 77 | + repo: context.repo.repo, |
| 78 | + body: `The changes in this PR were just released in [${release.name}](https://github.com/${context.repo.owner}/${context.repo.repo}/releases/tag/${release.tag_name}) 🎉.` |
| 79 | + }) |
| 80 | + } |
0 commit comments