From a0cf529452e3165d4eb67f067e27568cbe685d22 Mon Sep 17 00:00:00 2001 From: Andrii Lytovchenko Date: Sun, 12 Jun 2022 08:14:26 +0300 Subject: [PATCH 1/4] refactor: change github deployment workflow --- .github/workflows/deployment.yml | 122 ++++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 27 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 7c94bcd..ec0ba31 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -2,49 +2,117 @@ name: Deployment on: push: - tags: pull_request: + workflow_dispatch: + inputs: + check-ci: + description: "Require the CI to have passed for this commit" + required: true + default: "yes" + version: + description: "Override the release version number (e.g. 2.0.0a5)" jobs: deploy-pypi: name: PyPI deployment runs-on: "ubuntu-latest" if: github.event_name != 'push' || github.repository == 'DIRACGrid/COMDIRAC' + defaults: + run: + shell: bash -l {0} steps: - uses: actions/checkout@v2 + with: + token: ${{ secrets.PAT || github.token }} + - run: | + git fetch --prune --unshallow + git config --global user.email "ci@diracgrid.org" + git config --global user.name "DIRACGrid CI" + git clone https://github.com/DIRACGrid/DIRAC.git ../DIRAC - uses: actions/setup-python@v2 with: python-version: "3.9" - - name: Install dependencies - run: pip install build readme_renderer diraccfg + - name: Installing dependencies + run: | + python -m pip install \ + build \ + python-dateutil \ + pytz \ + readme_renderer \ + requests \ + setuptools_scm \ + six - name: Validate README for PyPI - run: python -m readme_renderer README.rst -o /tmp/README.html - - name: Make PEP-440 style release on GitHub - id: PEP-440 - if: github.event_name == 'push' run: | - TAG_NAME=${GITHUB_REF##*/} - NEW_STYLE=$(python -c "import diraccfg; major, minor, patch, pre = diraccfg.parseVersion('${TAG_NAME}'); print(f'{major}.{minor}.{patch}', f'a{pre}' if pre else '', sep='')") - echo "Converted ${TAG_NAME} version to ${NEW_STYLE}" - echo ::set-output name=tag_name::"v$NEW_STYLE" - echo ::set-output name=target_commitish::"$(git rev-parse HEAD)" - - name: Publish ${{ steps.PEP-440.outputs.tag_name }} release to GitHub - if: github.event_name == 'push' - uses: softprops/action-gh-release@v1 - with: - target_commitish: ${{ steps.PEP-440.outputs.target_commitish }} - body_path: release.notes - tag_name: ${{ steps.PEP-440.outputs.tag_name }} - - name: Get ${{ steps.PEP-440.outputs.tag_name }} tag - if: github.event_name == 'push' - uses: actions/checkout@v2 - with: - ref: ${{ steps.PEP-440.outputs.tag_name }} + python -m readme_renderer README.rst -o /tmp/README.html + - name: Prepare release notes + run: | + set -xeuo pipefail + IFS=$'\n\t' + PREV_VERSION=$(git describe --tags --abbrev=0 --match '*[0-9].[0-9]*' --exclude 'v[0-9]r*' --exclude 'v[0-9][0-9]r*') + REFERENCE_BRANCH=${GITHUB_REF#refs/heads/} + echo "Making release notes for ${REFERENCE_BRANCH} since ${PREV_VERSION}" + ../DIRAC/docs/diracdoctools/scripts/dirac-docs-get-release-notes.py \ + --token "${{ secrets.GITHUB_TOKEN }}" \ + --sinceTag "${PREV_VERSION}" \ + --branches "${REFERENCE_BRANCH}" \ + --repo "${{ github.repository }}" \ + > release.notes.new + cat release.notes.new + - name: Create tag if required + id: check-tag + run: | + set -xeuo pipefail + IFS=$'\n\t' + if [[ "${{ github.repository }}" == "DIRACGrid/COMDIRAC" ]]; then + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + if [[ "${{ github.event.ref }}" =~ ^refs/heads/(integration|rel-v([5-9]|[1-9][0-9]+)\.[0-9]+)$ ]]; then + echo "Will create a real release" + export NEW_VERSION="v${{ github.event.inputs.version }}" + if [[ "${NEW_VERSION}" == "v" ]]; then + NEW_VERSION=v$(python -m setuptools_scm | sed 's@Guessed Version @@g' | sed -E 's@(\.dev|\+g).+@@g') + export NEW_VERSION + fi + echo "Release will be named $NEW_VERSION" + # Validate the version + python -c $'from packaging.version import Version; v = Version('"'$NEW_VERSION'"$')\nif v.is_devrelease:\n raise ValueError(v)' + # Commit the release notes + mv release.notes release.notes.old + { + echo -e "[${NEW_VERSION}]" && \ + tail -n +2 release.notes.new | perl -0777pe 's/\n+$/\n\n/' && \ + cat release.notes.old; + } > release.notes + git add release.notes + git commit -m "docs: Add release notes for $NEW_VERSION" + git show + # Create the tag + git tag "$NEW_VERSION" + echo ::set-output name=create-release::true + echo ::set-output name=new-version::"$NEW_VERSION" + fi + fi + fi - name: Build distributions - run: python -m build + run: | + python -m build + - name: Make release on GitHub + if: steps.check-tag.outputs.create-release == 'true' + run: | + set -e + export NEW_VERSION=${{ steps.check-tag.outputs.new-version }} + echo "Pushing tagged release notes to ${GITHUB_REF#refs/heads/}" + git push "origin" "${GITHUB_REF#refs/heads/}" + echo "Making GitHub release for ${NEW_VERSION}" + ../DIRAC/.github/workflows/make_release.py \ + --repo="${{ github.repository }}" \ + --token="${{ secrets.GITHUB_TOKEN }}" \ + --version="${NEW_VERSION}" \ + --rev="$(git rev-parse HEAD)" \ + --release-notes-fn="release.notes.new" - name: Publish package on PyPI - if: github.event_name == 'push' - uses: pypa/gh-action-pypi-publish@master + if: steps.check-tag.outputs.create-release == 'true' + uses: pypa/gh-action-pypi-publish@release/v1 with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} From 16c5012fb3ea0b5289d9e25642ad328efec07b7f Mon Sep 17 00:00:00 2001 From: Andrii Lytovchenko Date: Sun, 12 Jun 2022 19:00:52 +0300 Subject: [PATCH 2/4] refactor: change github deployment workflow --- .github/workflows/deployment.yml | 115 +++++-------------------------- 1 file changed, 19 insertions(+), 96 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index ec0ba31..a3752c6 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -2,117 +2,40 @@ name: Deployment on: push: + tags: pull_request: - workflow_dispatch: - inputs: - check-ci: - description: "Require the CI to have passed for this commit" - required: true - default: "yes" - version: - description: "Override the release version number (e.g. 2.0.0a5)" jobs: deploy-pypi: name: PyPI deployment runs-on: "ubuntu-latest" if: github.event_name != 'push' || github.repository == 'DIRACGrid/COMDIRAC' - defaults: - run: - shell: bash -l {0} steps: - uses: actions/checkout@v2 - with: - token: ${{ secrets.PAT || github.token }} - - run: | - git fetch --prune --unshallow - git config --global user.email "ci@diracgrid.org" - git config --global user.name "DIRACGrid CI" - git clone https://github.com/DIRACGrid/DIRAC.git ../DIRAC - uses: actions/setup-python@v2 with: python-version: "3.9" - - name: Installing dependencies - run: | - python -m pip install \ - build \ - python-dateutil \ - pytz \ - readme_renderer \ - requests \ - setuptools_scm \ - six + - name: Install dependencies + run: pip install build readme_renderer diraccfg - name: Validate README for PyPI - run: | - python -m readme_renderer README.rst -o /tmp/README.html - - name: Prepare release notes - run: | - set -xeuo pipefail - IFS=$'\n\t' - PREV_VERSION=$(git describe --tags --abbrev=0 --match '*[0-9].[0-9]*' --exclude 'v[0-9]r*' --exclude 'v[0-9][0-9]r*') - REFERENCE_BRANCH=${GITHUB_REF#refs/heads/} - echo "Making release notes for ${REFERENCE_BRANCH} since ${PREV_VERSION}" - ../DIRAC/docs/diracdoctools/scripts/dirac-docs-get-release-notes.py \ - --token "${{ secrets.GITHUB_TOKEN }}" \ - --sinceTag "${PREV_VERSION}" \ - --branches "${REFERENCE_BRANCH}" \ - --repo "${{ github.repository }}" \ - > release.notes.new - cat release.notes.new - - name: Create tag if required - id: check-tag - run: | - set -xeuo pipefail - IFS=$'\n\t' - if [[ "${{ github.repository }}" == "DIRACGrid/COMDIRAC" ]]; then - if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then - if [[ "${{ github.event.ref }}" =~ ^refs/heads/(integration|rel-v([5-9]|[1-9][0-9]+)\.[0-9]+)$ ]]; then - echo "Will create a real release" - export NEW_VERSION="v${{ github.event.inputs.version }}" - if [[ "${NEW_VERSION}" == "v" ]]; then - NEW_VERSION=v$(python -m setuptools_scm | sed 's@Guessed Version @@g' | sed -E 's@(\.dev|\+g).+@@g') - export NEW_VERSION - fi - echo "Release will be named $NEW_VERSION" - # Validate the version - python -c $'from packaging.version import Version; v = Version('"'$NEW_VERSION'"$')\nif v.is_devrelease:\n raise ValueError(v)' - # Commit the release notes - mv release.notes release.notes.old - { - echo -e "[${NEW_VERSION}]" && \ - tail -n +2 release.notes.new | perl -0777pe 's/\n+$/\n\n/' && \ - cat release.notes.old; - } > release.notes - git add release.notes - git commit -m "docs: Add release notes for $NEW_VERSION" - git show - # Create the tag - git tag "$NEW_VERSION" - echo ::set-output name=create-release::true - echo ::set-output name=new-version::"$NEW_VERSION" - fi - fi - fi + run: python -m readme_renderer README.rst -o /tmp/README.html + - name: Publish ${GITHUB_REF##*/} release to GitHub + if: github.event_name == 'push' + uses: softprops/action-gh-release@v1 + with: + target_commitish: $(git rev-parse HEAD) + body_path: release.notes + tag_name: ${GITHUB_REF##*/} + - name: Get ${GITHUB_REF##*/} tag + if: github.event_name == 'push' + uses: actions/checkout@v2 + with: + ref: ${GITHUB_REF##*/} - name: Build distributions - run: | - python -m build - - name: Make release on GitHub - if: steps.check-tag.outputs.create-release == 'true' - run: | - set -e - export NEW_VERSION=${{ steps.check-tag.outputs.new-version }} - echo "Pushing tagged release notes to ${GITHUB_REF#refs/heads/}" - git push "origin" "${GITHUB_REF#refs/heads/}" - echo "Making GitHub release for ${NEW_VERSION}" - ../DIRAC/.github/workflows/make_release.py \ - --repo="${{ github.repository }}" \ - --token="${{ secrets.GITHUB_TOKEN }}" \ - --version="${NEW_VERSION}" \ - --rev="$(git rev-parse HEAD)" \ - --release-notes-fn="release.notes.new" + run: python -m build - name: Publish package on PyPI - if: steps.check-tag.outputs.create-release == 'true' - uses: pypa/gh-action-pypi-publish@release/v1 + if: github.event_name == 'push' + uses: pypa/gh-action-pypi-publish@master with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} From cbf3c222557d091a8ebaf2f614dd8ccfb8076fba Mon Sep 17 00:00:00 2001 From: Andrii Lytovchenko Date: Sun, 12 Jun 2022 19:01:42 +0300 Subject: [PATCH 3/4] refactor: change github deployment workflow --- release.notes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/release.notes b/release.notes index 098bc72..f4b0fa6 100644 --- a/release.notes +++ b/release.notes @@ -1,3 +1,5 @@ +[2.0.0a2] + [v1r3p3] CHANGE: (#83) convert ReadMe to RST NEW: (#80) add deployment action From 8063dfe1d224438bb66f8783ed34d265b246426e Mon Sep 17 00:00:00 2001 From: Andrii Lytovchenko Date: Sun, 12 Jun 2022 19:14:51 +0300 Subject: [PATCH 4/4] refactor: change github deployment workflow --- .github/workflows/deployment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index a3752c6..068723e 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -3,6 +3,7 @@ name: Deployment on: push: tags: + - 2.0.0a[0-9]+ pull_request: jobs: