From ce466121cdfa9067075c5fb59837a3a606a9d070 Mon Sep 17 00:00:00 2001 From: Chris Simpkins Date: Thu, 29 Oct 2020 21:33:29 -0400 Subject: [PATCH 1/8] add GH Action GitHub + PyPI release automation on git version tag pushes --- .github/workflows/publish-release.yml | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/publish-release.yml diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 000000000..6163b8b86 --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,43 @@ +on: + push: + tags: + - "v*" # Push events to matching `v*` version srings. e.g. v1.0, v20.15.10 + +name: Create and Publish Release + +jobs: + build: + name: Create and Publish Release + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.9] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install release dependencies + run: | + python -m pip install --upgrade pip + pip install --upgrade setuptools wheel twine + - name: Create GitHub release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + body: | + Please see the root of the repository for the CHANGELOG.md + draft: false + prerelease: false + - name: Build and publish to PyPI + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* From 799c4624b926ee34e547754da889557633f7ee57 Mon Sep 17 00:00:00 2001 From: Marc Foley Date: Mon, 9 Nov 2020 13:36:40 +0000 Subject: [PATCH 2/8] Use the annotated tag message for release body --- .github/workflows/publish-release.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 6163b8b86..4ba9a1aa7 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -22,6 +22,14 @@ jobs: run: | python -m pip install --upgrade pip pip install --upgrade setuptools wheel twine + - name: Get release notes + id: release_notes + run: | + CHANGELOG=$(git tag -l --format='%(contents)' ${{ github.ref }}) + CHANGELOG="${CHANGELOG//'%'/'%25'}" + CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" + CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" + echo "::set-output name=changelog::$CHANGELOG" - name: Create GitHub release id: create_release uses: actions/create-release@v1 @@ -30,8 +38,7 @@ jobs: with: tag_name: ${{ github.ref }} release_name: ${{ github.ref }} - body: | - Please see the root of the repository for the CHANGELOG.md + body: ${{ steps.release_notes.outputs.changelog }} draft: false prerelease: false - name: Build and publish to PyPI From 0be67c45678a98b6c02dd56d4f933976cb35b361 Mon Sep 17 00:00:00 2001 From: Marc Foley Date: Mon, 9 Nov 2020 14:31:01 +0000 Subject: [PATCH 3/8] release: remove linebreak formats --- .github/workflows/publish-release.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 4ba9a1aa7..bfd3d360b 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -26,9 +26,6 @@ jobs: id: release_notes run: | CHANGELOG=$(git tag -l --format='%(contents)' ${{ github.ref }}) - CHANGELOG="${CHANGELOG//'%'/'%25'}" - CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" - CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" echo "::set-output name=changelog::$CHANGELOG" - name: Create GitHub release id: create_release From c5342e94db8800e2fca30223bcab3faaf946c6c2 Mon Sep 17 00:00:00 2001 From: Marc Foley Date: Mon, 9 Nov 2020 18:57:46 +0000 Subject: [PATCH 4/8] release: output annotated tag message in markdown --- .github/workflows/publish-release.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index bfd3d360b..c8f412673 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -13,10 +13,11 @@ jobs: matrix: python-version: [3.9] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@master - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: + fetch-depth: 0 python-version: ${{ matrix.python-version }} - name: Install release dependencies run: | @@ -25,7 +26,15 @@ jobs: - name: Get release notes id: release_notes run: | - CHANGELOG=$(git tag -l --format='%(contents)' ${{ github.ref }}) + git fetch --tags --force + GITHUB_REF=${{ github.ref }} + TAG_NAME=${GITHUB_REF/refs\/tags\//} + echo "Got tag: $TAG_NAME" + CHANGELOG=$(git tag -l --format='%(contents)' $TAG_NAME) + CHANGELOG="${CHANGELOG//'%'/'%25'}" + CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" + CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" + echo "Got changelog: $CHANGELOG" echo "::set-output name=changelog::$CHANGELOG" - name: Create GitHub release id: create_release @@ -35,7 +44,7 @@ jobs: with: tag_name: ${{ github.ref }} release_name: ${{ github.ref }} - body: ${{ steps.release_notes.outputs.changelog }} + body: "${{ steps.release_notes.outputs.changelog }}" draft: false prerelease: false - name: Build and publish to PyPI From c0890d1666ad404b2c0c4d7bb887f9eec6618bac Mon Sep 17 00:00:00 2001 From: Marc Foley Date: Mon, 9 Nov 2020 21:15:22 +0000 Subject: [PATCH 5/8] cleanup and add comments --- .github/workflows/publish-release.yml | 33 ++++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index c8f412673..3b7ad38fc 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -9,44 +9,55 @@ jobs: build: name: Create and Publish Release runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.9] + steps: - uses: actions/checkout@master - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python uses: actions/setup-python@v2 with: - fetch-depth: 0 - python-version: ${{ matrix.python-version }} + python-version: '3.x' + - name: Install release dependencies run: | python -m pip install --upgrade pip pip install --upgrade setuptools wheel twine + - name: Get release notes id: release_notes run: | + # By default, GH Actions checkout will only fetch a single commit. + # For us to extract the release notes, we need to fetch the tags + # and tag annotations as well. + # https://github.com/actions/checkout/issues/290 git fetch --tags --force - GITHUB_REF=${{ github.ref }} TAG_NAME=${GITHUB_REF/refs\/tags\//} - echo "Got tag: $TAG_NAME" CHANGELOG=$(git tag -l --format='%(contents)' $TAG_NAME) + # we have to escape all new line characters and carriage + # returns before passing them into set-output otherwise the + # body content of the release will only contain the first line + # https://github.com/actions/create-release/issues/38#issuecomment-640072234 CHANGELOG="${CHANGELOG//'%'/'%25'}" CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" - echo "Got changelog: $CHANGELOG" echo "::set-output name=changelog::$CHANGELOG" + - name: Create GitHub release id: create_release - uses: actions/create-release@v1 + # create-release@v1 doesn't support the body arg so we use + # create-release@master instead. + uses: actions/create-release@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ github.ref }} release_name: ${{ github.ref }} - body: "${{ steps.release_notes.outputs.changelog }}" + # To set the body arg, we fetch the changelog variable we created + # in the previous step. Implementation is based on + # the third example in https://github.com/actions/create-release/pull/11 + body: ${{ steps.release_notes.outputs.changelog }} draft: false prerelease: false + - name: Build and publish to PyPI env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} From 316464964438eab2586cb46964bc51fa14ad641d Mon Sep 17 00:00:00 2001 From: Marc Foley Date: Tue, 10 Nov 2020 09:15:21 +0000 Subject: [PATCH 6/8] Implement Nikolaus feedback --- .github/workflows/publish-release.yml | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 3b7ad38fc..5bfa71b12 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -31,15 +31,7 @@ jobs: # https://github.com/actions/checkout/issues/290 git fetch --tags --force TAG_NAME=${GITHUB_REF/refs\/tags\//} - CHANGELOG=$(git tag -l --format='%(contents)' $TAG_NAME) - # we have to escape all new line characters and carriage - # returns before passing them into set-output otherwise the - # body content of the release will only contain the first line - # https://github.com/actions/create-release/issues/38#issuecomment-640072234 - CHANGELOG="${CHANGELOG//'%'/'%25'}" - CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" - CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" - echo "::set-output name=changelog::$CHANGELOG" + echo "$(git tag -l --format='%(contents)' $TAG_NAME)" > CHANGELOG.md - name: Create GitHub release id: create_release @@ -51,10 +43,7 @@ jobs: with: tag_name: ${{ github.ref }} release_name: ${{ github.ref }} - # To set the body arg, we fetch the changelog variable we created - # in the previous step. Implementation is based on - # the third example in https://github.com/actions/create-release/pull/11 - body: ${{ steps.release_notes.outputs.changelog }} + body_path: CHANGELOG.md draft: false prerelease: false From ddbef46d8376fce28d4e09806bad3249bfc589ea Mon Sep 17 00:00:00 2001 From: Marc Foley Date: Tue, 10 Nov 2020 09:57:40 +0000 Subject: [PATCH 7/8] repin to v1 --- .github/workflows/publish-release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 5bfa71b12..776f35a9f 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -37,7 +37,8 @@ jobs: id: create_release # create-release@v1 doesn't support the body arg so we use # create-release@master instead. - uses: actions/create-release@master + # CS attempt + uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: From 12acc22d3b50d2bc4298c5eee5aef90595e58df6 Mon Sep 17 00:00:00 2001 From: Marc Foley Date: Tue, 10 Nov 2020 10:15:36 +0000 Subject: [PATCH 8/8] use tempfile --- .github/workflows/publish-release.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 776f35a9f..e3b391473 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -31,20 +31,17 @@ jobs: # https://github.com/actions/checkout/issues/290 git fetch --tags --force TAG_NAME=${GITHUB_REF/refs\/tags\//} - echo "$(git tag -l --format='%(contents)' $TAG_NAME)" > CHANGELOG.md + echo "$(git tag -l --format='%(contents)' $TAG_NAME)" > "${{ runner.temp }}/CHANGELOG.md" - name: Create GitHub release id: create_release - # create-release@v1 doesn't support the body arg so we use - # create-release@master instead. - # CS attempt uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ github.ref }} release_name: ${{ github.ref }} - body_path: CHANGELOG.md + body_path: "${{ runner.temp }}/CHANGELOG.md" draft: false prerelease: false