From e34653ec97a20e013b791cadd94ed814ed30834e Mon Sep 17 00:00:00 2001 From: s-weigand Date: Tue, 3 Nov 2020 15:55:55 +0100 Subject: [PATCH 1/8] Add major-minor-release workflow --- .github/workflows/publish-major-minor.py | 17 ++++++++++++ .github/workflows/publish-major-minor.yml | 33 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 .github/workflows/publish-major-minor.py create mode 100644 .github/workflows/publish-major-minor.yml diff --git a/.github/workflows/publish-major-minor.py b/.github/workflows/publish-major-minor.py new file mode 100644 index 0000000..b728046 --- /dev/null +++ b/.github/workflows/publish-major-minor.py @@ -0,0 +1,17 @@ +import sys + +from packaging.version import parse + +print(sys.version_info) +tag_ref = sys.argv[1] +tag_name = tag_ref.split("/")[-1] +print(f"tag_name: {tag_name}") +version = parse(tag_name) +print(f"version: {version}") +if not (version.is_prerelease): + print("Creating new major and minor tags!") + print(f"::set-output name=original_tag_name::{tag_name}") + print(f"::set-output name=major_version::v{version.major}") + print(f"::set-output name=minor_version::v{version.major}.{version.minor}") +else: + print("No tags created (dev or pre version)!") diff --git a/.github/workflows/publish-major-minor.yml b/.github/workflows/publish-major-minor.yml new file mode 100644 index 0000000..d1a1778 --- /dev/null +++ b/.github/workflows/publish-major-minor.yml @@ -0,0 +1,33 @@ +name: "Publish Major-Minor-Tags" +on: + push: + tags: + - "v*" + +jobs: + push-tags: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install packaging + run: pip install -U packaging + - name: Get versions + id: get_versions + run: python .github/workflows/publish-major-minor.py ${{ github.ref }} + - name: Push Tags Version + if: steps.get_versions.outputs.original_tag_name != '' + env: + original_tag_name: ${{ steps.get_versions.outputs.original_tag_name }} + major_version: ${{ steps.get_versions.outputs.major_version }} + minor_version: ${{ steps.get_versions.outputs.minor_version }} + run: | + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + git tag -a $major_version -m "original tag: $original_tag_name" + git tag -a $minor_version -m "original tag: $original_tag_name" + git push origin $major_version -f + git push origin $minor_version -f From b78d2e95c3cdb379a38c56a15e05dea40f8f4027 Mon Sep 17 00:00:00 2001 From: s-weigand Date: Wed, 4 Nov 2020 00:23:22 +0100 Subject: [PATCH 2/8] Use 'shell : python' instead of script --- .github/workflows/publish-major-minor.py | 17 ----------------- .github/workflows/publish-major-minor.yml | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 .github/workflows/publish-major-minor.py diff --git a/.github/workflows/publish-major-minor.py b/.github/workflows/publish-major-minor.py deleted file mode 100644 index b728046..0000000 --- a/.github/workflows/publish-major-minor.py +++ /dev/null @@ -1,17 +0,0 @@ -import sys - -from packaging.version import parse - -print(sys.version_info) -tag_ref = sys.argv[1] -tag_name = tag_ref.split("/")[-1] -print(f"tag_name: {tag_name}") -version = parse(tag_name) -print(f"version: {version}") -if not (version.is_prerelease): - print("Creating new major and minor tags!") - print(f"::set-output name=original_tag_name::{tag_name}") - print(f"::set-output name=major_version::v{version.major}") - print(f"::set-output name=minor_version::v{version.major}.{version.minor}") -else: - print("No tags created (dev or pre version)!") diff --git a/.github/workflows/publish-major-minor.yml b/.github/workflows/publish-major-minor.yml index d1a1778..6938514 100644 --- a/.github/workflows/publish-major-minor.yml +++ b/.github/workflows/publish-major-minor.yml @@ -17,7 +17,24 @@ jobs: run: pip install -U packaging - name: Get versions id: get_versions - run: python .github/workflows/publish-major-minor.py ${{ github.ref }} + shell: python + run: | + import sys + from packaging.version import parse + print(sys.version_info) + tag_ref = "${{ github.ref }}" + tag_name = tag_ref.split("/")[-1] + print(f"tag_name: {tag_name}") + version = parse(tag_name) + print(f"version: {version}") + if not (version.is_prerelease): + print("Creating new major and minor tags!") + print(f"::set-output name=original_tag_name::{tag_name}") + print(f"::set-output name=major_version::v{version.major}") + print(f"::set-output name=minor_version::v{version.major}.{version.minor}") + else: + print("No tags created (dev or pre version)!") + - name: Push Tags Version if: steps.get_versions.outputs.original_tag_name != '' env: From 5baaafca44b91bd917c3fb5560bacd6f0658f0f5 Mon Sep 17 00:00:00 2001 From: s-weigand Date: Wed, 4 Nov 2020 00:34:14 +0100 Subject: [PATCH 3/8] Applied requested changes --- .github/workflows/publish-major-minor.yml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/publish-major-minor.yml b/.github/workflows/publish-major-minor.yml index 6938514..1745871 100644 --- a/.github/workflows/publish-major-minor.yml +++ b/.github/workflows/publish-major-minor.yml @@ -14,20 +14,19 @@ jobs: with: python-version: 3.8 - name: Install packaging - run: pip install -U packaging + run: python -m pip install -U packaging --user - name: Get versions id: get_versions shell: python run: | - import sys from packaging.version import parse - print(sys.version_info) + tag_ref = "${{ github.ref }}" tag_name = tag_ref.split("/")[-1] - print(f"tag_name: {tag_name}") version = parse(tag_name) + print(f"tag_name: {tag_name}") print(f"version: {version}") - if not (version.is_prerelease): + if not version.is_prerelease: print("Creating new major and minor tags!") print(f"::set-output name=original_tag_name::{tag_name}") print(f"::set-output name=major_version::v{version.major}") @@ -42,9 +41,11 @@ jobs: major_version: ${{ steps.get_versions.outputs.major_version }} minor_version: ${{ steps.get_versions.outputs.minor_version }} run: | - git config --global user.email "github-actions[bot]@users.noreply.github.com" - git config --global user.name "github-actions[bot]" - git tag -a $major_version -m "original tag: $original_tag_name" - git tag -a $minor_version -m "original tag: $original_tag_name" - git push origin $major_version -f - git push origin $minor_version -f + git config user.email 'github-actions[bot]@users.noreply.github.com' + git config user.name 'github-actions[bot]' + git tag --annotate '${{ env.major_version }}' \ + --message='original tag: ${{ env.original_tag_name }}' + git tag --annotate '${{ env.minor_version }}' \ + --message='original tag: ${{ env.original_tag_name }}' + git push origin '${{ env.major_version }}' --force-with-lease + git push origin '${{ env.minor_version }}' --force-with-lease From 54e3ca66c36b71117ba53dd35818d57cd140efe6 Mon Sep 17 00:00:00 2001 From: Sebastian Weigand Date: Fri, 6 Nov 2020 15:34:32 +0100 Subject: [PATCH 4/8] Unnest outpust creation Co-authored-by: Sviatoslav Sydorenko --- .github/workflows/publish-major-minor.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-major-minor.yml b/.github/workflows/publish-major-minor.yml index 1745871..7e845db 100644 --- a/.github/workflows/publish-major-minor.yml +++ b/.github/workflows/publish-major-minor.yml @@ -26,14 +26,14 @@ jobs: version = parse(tag_name) print(f"tag_name: {tag_name}") print(f"version: {version}") - if not version.is_prerelease: - print("Creating new major and minor tags!") - print(f"::set-output name=original_tag_name::{tag_name}") - print(f"::set-output name=major_version::v{version.major}") - print(f"::set-output name=minor_version::v{version.major}.{version.minor}") - else: + if version.is_prerelease: print("No tags created (dev or pre version)!") + exit(0) + print("Creating new major and minor tags!") + print(f"::set-output name=original_tag_name::{tag_name}") + print(f"::set-output name=major_version::v{version.major}") + print(f"::set-output name=minor_version::v{version.major}.{version.minor}") - name: Push Tags Version if: steps.get_versions.outputs.original_tag_name != '' env: From 5fbbe92f7f46fdcc3bb7f74fcb35739383ed5d6e Mon Sep 17 00:00:00 2001 From: Sebastian Weigand Date: Fri, 6 Nov 2020 15:39:23 +0100 Subject: [PATCH 5/8] Make Tag pushing atomic Co-authored-by: Sviatoslav Sydorenko --- .github/workflows/publish-major-minor.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-major-minor.yml b/.github/workflows/publish-major-minor.yml index 7e845db..ac81403 100644 --- a/.github/workflows/publish-major-minor.yml +++ b/.github/workflows/publish-major-minor.yml @@ -47,5 +47,6 @@ jobs: --message='original tag: ${{ env.original_tag_name }}' git tag --annotate '${{ env.minor_version }}' \ --message='original tag: ${{ env.original_tag_name }}' - git push origin '${{ env.major_version }}' --force-with-lease - git push origin '${{ env.minor_version }}' --force-with-lease + git push --force --atomic origin \ + '${{ env.major_version }}' \ + '${{ env.minor_version }}' From 1ef704e0ad5ba86cd7f2548f62a04357cbef86b7 Mon Sep 17 00:00:00 2001 From: s-weigand Date: Fri, 6 Nov 2020 15:48:44 +0100 Subject: [PATCH 6/8] Split up git user setup, tag creation and tag pushing in separate tasks See https://github.com/pypa/gh-action-pypi-publish/pull/45#discussion_r517258942 --- .github/workflows/publish-major-minor.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-major-minor.yml b/.github/workflows/publish-major-minor.yml index ac81403..6a12411 100644 --- a/.github/workflows/publish-major-minor.yml +++ b/.github/workflows/publish-major-minor.yml @@ -33,20 +33,28 @@ jobs: print("Creating new major and minor tags!") print(f"::set-output name=original_tag_name::{tag_name}") print(f"::set-output name=major_version::v{version.major}") - print(f"::set-output name=minor_version::v{version.major}.{version.minor}") - - name: Push Tags Version + print(f"::set-output name=minor_version::v{version.major}.{version.minor}") + - name: Setup git user as [bot] + run: | + git config user.email 'github-actions[bot]@users.noreply.github.com' + git config user.name 'github-actions[bot]' + - name: Create major + minor tags if: steps.get_versions.outputs.original_tag_name != '' env: original_tag_name: ${{ steps.get_versions.outputs.original_tag_name }} major_version: ${{ steps.get_versions.outputs.major_version }} minor_version: ${{ steps.get_versions.outputs.minor_version }} run: | - git config user.email 'github-actions[bot]@users.noreply.github.com' - git config user.name 'github-actions[bot]' git tag --annotate '${{ env.major_version }}' \ --message='original tag: ${{ env.original_tag_name }}' git tag --annotate '${{ env.minor_version }}' \ --message='original tag: ${{ env.original_tag_name }}' + - name: Push major + minor tags + if: steps.get_versions.outputs.original_tag_name != '' + env: + major_version: ${{ steps.get_versions.outputs.major_version }} + minor_version: ${{ steps.get_versions.outputs.minor_version }} + run: | git push --force --atomic origin \ '${{ env.major_version }}' \ '${{ env.minor_version }}' From bf26813dfef31a93f03813f4e28f4d4d4cff8d28 Mon Sep 17 00:00:00 2001 From: s-weigand Date: Fri, 6 Nov 2020 15:58:16 +0100 Subject: [PATCH 7/8] Improved tag message --- .github/workflows/publish-major-minor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-major-minor.yml b/.github/workflows/publish-major-minor.yml index 6a12411..50ce177 100644 --- a/.github/workflows/publish-major-minor.yml +++ b/.github/workflows/publish-major-minor.yml @@ -46,9 +46,9 @@ jobs: minor_version: ${{ steps.get_versions.outputs.minor_version }} run: | git tag --annotate '${{ env.major_version }}' \ - --message='original tag: ${{ env.original_tag_name }}' + --message='Major version tag of: ${{ env.original_tag_name }}' git tag --annotate '${{ env.minor_version }}' \ - --message='original tag: ${{ env.original_tag_name }}' + --message='Minor version tag of: ${{ env.original_tag_name }}' - name: Push major + minor tags if: steps.get_versions.outputs.original_tag_name != '' env: From aabe83c06d3dfd95b96c1c792792f09b2adba615 Mon Sep 17 00:00:00 2001 From: s-weigand Date: Mon, 9 Nov 2020 17:17:03 +0100 Subject: [PATCH 8/8] Added sha of original commit to tag commit message --- .github/workflows/publish-major-minor.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-major-minor.yml b/.github/workflows/publish-major-minor.yml index 50ce177..c441328 100644 --- a/.github/workflows/publish-major-minor.yml +++ b/.github/workflows/publish-major-minor.yml @@ -46,9 +46,11 @@ jobs: minor_version: ${{ steps.get_versions.outputs.minor_version }} run: | git tag --annotate '${{ env.major_version }}' \ - --message='Major version tag of: ${{ env.original_tag_name }}' + --message='Major version tag of: ${{ env.original_tag_name }}' \ + --message="Original tag SHA1: $(git rev-parse ${{ env.original_tag_name }})" git tag --annotate '${{ env.minor_version }}' \ - --message='Minor version tag of: ${{ env.original_tag_name }}' + --message='Minor version tag of: ${{ env.original_tag_name }}' \ + --message="Original tag SHA1: $(git rev-parse ${{ env.original_tag_name }})" - name: Push major + minor tags if: steps.get_versions.outputs.original_tag_name != '' env: