From d5a72dc425655b3dcde302c8c54a207479fcd375 Mon Sep 17 00:00:00 2001 From: Bryce Willey Date: Mon, 31 Oct 2022 15:25:38 -0400 Subject: [PATCH 1/2] Teams bump hook, in a github action Fixes #547 Still need to test, will have to copy and do in a different repo --- .github/workflows/publish.yml | 78 ++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6249c98a..cc19d6af 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,13 +1,17 @@ -name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI +name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI and announce to teams on: push jobs: build-n-publish: - name: Build and publish Python 🐍 distributions 📦 to PyPI runs-on: ubuntu-20.04 + + env: + TEAMS_BUMP_WEBHOOK: ${{ secrets.TEAMS_BUMP_WEBHOOK }} + + name: Build and publish Python 🐍 distributions 📦 to PyPI steps: - - uses: actions/checkout@master + - uses: actions/checkout@v2 - name: Set up Python 3.9 uses: actions/setup-python@v1 with: @@ -31,9 +35,73 @@ jobs: --sdist --wheel --outdir dist/ + - name: Ensure github tag is the same as the pypi tag + run: | + new_version=$(grep version= setup.py | cut -d\' -f 2) + [ "$GITHUB_REF_NAME" = "v$new_version" ] + - name: ${{ failure() }} + run: | + new_version=$(grep version= setup.py | cut -d\' -f 2) + echo "Github tag name ($GITHUB_REF_NAME) doesn't match the setup.py version ($nev_version). Not publishing to pypi" - name: Publish distribution 📦 to PyPI - if: startsWith(github.ref, 'refs/tags') + if: ${{ success() && startsWith(github.ref, 'refs/tags') }} uses: pypa/gh-action-pypi-publish@master with: user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file + password: ${{ secrets.PYPI_API_TOKEN }} + - name: Announce to teams + if: ${{ success() && startsWith(github.ref, 'refs/tags') }} + run: | + project_name=$(echo $GITHUB_REPO | cut -d '/' -f2 | cut -d '-' -f2) + new_version=$(grep version= setup.py | cut -d\' -f 2) + tag_url="https://$GITHUB_SERVER_URL/$GITHUB_REPO/releases/tag/$GITHUB_REF_NAME" + sed -e "s/{{version}}/$new_version/g; s/{{link_version}}/$GITHUB_REF_NAME/g; s/{{project_name}}/$project_name/g; s/{{org_repo_name}}/$GITHUB_REPO/g; s/{{tag_url}}/$tag_url/g;" << EOF > teams_msg_to_send.json + { + "@type": "MessageCard", + "@context": "https://schema.org/extensions", + "summary": "{{project_name}} Version released", + "themeColor": "0078D7", + "title": "{{project_name}} Version {{version}} released", + "sections": [ + { + "activityTitle": "Version {{version}}", + "activityImage": "https://avatars.githubusercontent.com/u/33028765?s=200", + "facts": [ + { + "name": "Repository:", + "value": "{{org_repo_name}}" + }, + { + "name": "Tag", + "value": "v{{version}}" + } + ], + "text": "" + } + ], + "potentialAction": [ + { + "@type": "OpenUri", + "name": "See Changelog", + "targets": [ + { + "os": "default", + "uri": "https://github.com/{{org_repo_name}}/blob/main/CHANGELOG.md#version-{{link_version}}" + } + ] + }, + { + "@type": "OpenUri", + "name": "View in GitHub", + "targets": [ + { + "os": "default", + "uri": "{{tag_url}}" + } + ] + } + ] + } + EOF + curl -H "Content-Type:application/json" -d "@teams_msg_to_send.json" "$TEAMS_BUMP_WEBHOOK" + From ea478c2e788466a2a1457c320e22904fe013c4f4 Mon Sep 17 00:00:00 2001 From: Bryce Willey Date: Wed, 2 Nov 2022 17:01:05 -0400 Subject: [PATCH 2/2] Fixed publish.yml / announce to TEAMS * Don't check if the ref equals the version on branches, only tags * Use `|` instead of `/`, otherwise sed can't use repo names and URLs. --- .github/workflows/publish.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cc19d6af..5eed9aaa 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -35,7 +35,8 @@ jobs: --sdist --wheel --outdir dist/ - - name: Ensure github tag is the same as the pypi tag + - if: ${{ success() && startsWith(github.ref, 'refs/tags') }} + name: Ensure github tag is the same as the pypi tag run: | new_version=$(grep version= setup.py | cut -d\' -f 2) [ "$GITHUB_REF_NAME" = "v$new_version" ] @@ -45,17 +46,16 @@ jobs: echo "Github tag name ($GITHUB_REF_NAME) doesn't match the setup.py version ($nev_version). Not publishing to pypi" - name: Publish distribution 📦 to PyPI if: ${{ success() && startsWith(github.ref, 'refs/tags') }} - uses: pypa/gh-action-pypi-publish@master + uses: pypa/gh-action-pypi-publish@release/v1 with: - user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} - name: Announce to teams if: ${{ success() && startsWith(github.ref, 'refs/tags') }} run: | - project_name=$(echo $GITHUB_REPO | cut -d '/' -f2 | cut -d '-' -f2) + project_name=$(echo $GITHUB_REPOSITORY | cut -d '/' -f2 | cut -d '-' -f2) new_version=$(grep version= setup.py | cut -d\' -f 2) - tag_url="https://$GITHUB_SERVER_URL/$GITHUB_REPO/releases/tag/$GITHUB_REF_NAME" - sed -e "s/{{version}}/$new_version/g; s/{{link_version}}/$GITHUB_REF_NAME/g; s/{{project_name}}/$project_name/g; s/{{org_repo_name}}/$GITHUB_REPO/g; s/{{tag_url}}/$tag_url/g;" << EOF > teams_msg_to_send.json + tag_url="https://$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$GITHUB_REF_NAME" + sed -e "s/{{version}}/$new_version/g; s/{{link_version}}/$GITHUB_REF_NAME/g; s/{{project_name}}/$project_name/g; s|{{org_repo_name}}|$GITHUB_REPOSITORY|g; s|{{tag_url}}|$tag_url|g;" << EOF > teams_msg_to_send.json { "@type": "MessageCard", "@context": "https://schema.org/extensions",