|
| 1 | +# Good example resources |
| 2 | +# https://riggaroo.dev/using-github-actions-to-automate-our-release-process/ |
| 3 | +# https://blog.eizinger.io/12274/using-github-actions-to-automate-gitflow-style-releases |
| 4 | + |
| 5 | +name: Release a new version of pandas_flavor |
| 6 | + |
| 7 | +on: |
| 8 | + |
| 9 | + # The below workflow_dispatch section is for a "manual" kick off of the |
| 10 | + # auto-release script. To cut a new release, navigate to the Actions section |
| 11 | + # of the repo and select this workflow (Auto-release) on the right hand side. |
| 12 | + # Then, click "Run workflow" and you will be prompted to input the new |
| 13 | + # version (which should be major, minor, or patch). |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + version_name: |
| 17 | + description: "One of major, minor, or patch" |
| 18 | + required: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + release: |
| 22 | + name: Create a new release |
| 23 | + runs-on: ubuntu-latest |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v2 |
| 28 | + |
| 29 | + - name: Pull latest commits of dev branch |
| 30 | + run: | |
| 31 | + git checkout main |
| 32 | + git pull |
| 33 | +
|
| 34 | + # See https://github.com/marketplace/actions/wait-on-check |
| 35 | + # TODO: Fix this later (have every push to dev trigger a test suite run) |
| 36 | + # - name: Ensure all tests are passing on dev |
| 37 | + |
| 38 | + # with: |
| 39 | + # ref: dev # can be commit SHA or tag |
| 40 | + # check-name: pyjanitor tests |
| 41 | + # repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + # wait-interval: 60 # seconds |
| 43 | + |
| 44 | + - name: Setup Python |
| 45 | + uses: actions/setup-python@v2 |
| 46 | + |
| 47 | + - name: Install bump2version and wheel |
| 48 | + run: python -m pip install bumpversion wheel # "bumpversion" installs bump2version |
| 49 | + |
| 50 | + - name: Dry run bumpversion |
| 51 | + run: | |
| 52 | + bumpversion --dry-run ${{ github.event.inputs.version_name }} --allow-dirty --verbose |
| 53 | +
|
| 54 | + # This is lifted directly from the bump2version docs. |
| 55 | + # Version number will be saved in `env` section of each consecutive stage |
| 56 | + - name: Store new version number |
| 57 | + run: echo "version_number=`bumpversion --dry-run --list ${{ github.event.inputs.version_name }} | grep new_version | sed -r s,"^.*=",,`" >> $GITHUB_ENV |
| 58 | + |
| 59 | + - name: Display new version number |
| 60 | + run: | |
| 61 | + echo "version_name: ${{ github.event.inputs.version_name }}" |
| 62 | + echo "version_number: v${{ env.version_number }}" |
| 63 | +
|
| 64 | + # See https://github.com/thomaseizinger/keep-a-changelog-new-release |
| 65 | + - name: Update Changelog |
| 66 | + uses: thomaseizinger/keep-a-changelog-new-release@v1 |
| 67 | + with: |
| 68 | + version: v${{ env.version_number }} |
| 69 | + |
| 70 | + - name: Commit CHANGELOG updates |
| 71 | + run: | |
| 72 | + git config --global user.email "[email protected]" |
| 73 | + git config --global user.name "GitHub Bot" |
| 74 | + git add . |
| 75 | + git commit -m "Update CHANGELOG for auto-release v${{ env.version_number }}" |
| 76 | +
|
| 77 | + - name: Ensure repo status is clean |
| 78 | + run: git status |
| 79 | + |
| 80 | + - name: Run bumpversion |
| 81 | + run: bumpversion ${{ github.event.inputs.version_name }} --verbose |
| 82 | + |
| 83 | + - name: Ensure tag creation |
| 84 | + run: git tag | grep ${{ env.version_number }} |
| 85 | + |
| 86 | + - name: Build package |
| 87 | + run: | |
| 88 | + rm -f dist/* |
| 89 | + python setup.py sdist bdist_wheel |
| 90 | +
|
| 91 | + - name: Publish package |
| 92 | + uses: pypa/gh-action-pypi-publish@master |
| 93 | + with: |
| 94 | + user: __token__ |
| 95 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 96 | + |
| 97 | + - name: Push changes with tags |
| 98 | + run: git push && git push --tags |
| 99 | + |
| 100 | + # This will create an actual pointer in the "Release" section of the GitHub repo |
| 101 | + # The intent is to always have "latest" point to <this> release |
| 102 | + - name: Create release in GitHub repo |
| 103 | + uses: ncipollo/release-action@v1 |
| 104 | + with: |
| 105 | + body: "Contribution details can be found in CHANGELOG.md" |
| 106 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + tag: v${{ env.version_number}} |
| 108 | + |
| 109 | + - name: Ensure complete |
| 110 | + run: echo "Auto-release complete!" |
0 commit comments