From 10b551705e3337d153e89722fe8a40faea00d588 Mon Sep 17 00:00:00 2001 From: Jan Richter Date: Wed, 13 Nov 2024 16:25:04 +0100 Subject: [PATCH] Release workflow This is an introduction to pre-release and release wokflows. The pre-release will build the current main branch a upload it into TEST PyPi repo to test out the current build. The release workflow will generate new autils major or minor input based on the release. Then it will do the build and upload it to PyPi. Reference: #21 Signed-off-by: Jan Richter --- .github/workflows/pre-release.yml | 69 +++++++++++++++++++++++++ .github/workflows/release.yml | 83 +++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 .github/workflows/pre-release.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml new file mode 100644 index 0000000..ca64720 --- /dev/null +++ b/.github/workflows/pre-release.yml @@ -0,0 +1,69 @@ +# must do before using this action: +# - set up RELEASE_TOKEN in secrets of the repository avocado-framework/avocado +# - set up RTD_TOKEN in secrets to update readthedocs +# - set up two tokens for twine: PYPI_USER and PYPI_PASSWD + +name: Pre-Release +on: workflow_dispatch + +jobs: + + release-test: + name: Release pipeline + runs-on: ubuntu-latest + container: + image: fedora:34 + env: + VERSION: ${{ github.event.inputs.version }} + DEVEL_NAME: ${{ github.event.inputs.devel_name }} + DEVEL_MAIL: ${{ github.event.inputs.devel_mail }} + PYTHON: /usr/bin/python3 + TOKEN_RTD: ${{ secrets.RTD_TOKEN }} + URL: "https://readthedocs.org/api/v3/projects/${{ github.event.inputs.rtd_project }}" + + steps: + - name: Generate token + id: generate_token + uses: tibdex/github-app-token@021a2405c7f990db57f5eae5397423dcc554159c + with: + app_id: ${{ secrets.MR_AVOCADO_ID }} + installation_id: ${{ secrets.MR_AVOCADO_INSTALLATION_ID }} + private_key: ${{ secrets.MR_AVOCADO_PRIVATE_KEY }} + - name: install required packages + run: dnf -y install git python3-pip + - uses: actions/checkout@v4 + with: + persist-credentials: false + fetch-depth: 0 + - name: Build wheel + run: | + python3 -m pip install build + mkdir PYPI_UPLOAD + python3 -m build -o PYPI_UPLOAD + - name: Save wheel as artifact + uses: actions/upload-artifact@v4 + with: + name: wheel + path: ${{github.workspace}}/PYPI_UPLOAD/ + retention-days: 3 + + publish-to-test-pypi: + name: Publish Avocado to TestPyPI + needs: + - release-test + runs-on: ubuntu-latest + environment: + name: pypi + url: https://test.pypi.org/project/autils + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + steps: + - name: Download all the wheels + uses: actions/download-artifact@v4 + with: + name: wheel + path: dist/ + - name: Publish avocado to test PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c54c7c0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,83 @@ +# must do before using this action: +# - set up RELEASE_TOKEN in secrets of the repository avocado-framework/avocado +# - set up RTD_TOKEN in secrets to update readthedocs +# - set up two tokens for twine: PYPI_USER and PYPI_PASSWD + +name: Release +on: + workflow_dispatch: + inputs: + version: + description: 'Release version type' + type: choice + options: + - mayor + - minor + default: 'mayor' + +jobs: + + release: + name: Release pipeline + runs-on: ubuntu-latest + container: + image: fedora:34 + env: + VERSION: ${{ github.event.inputs.version }} + steps: + - name: Generate token + id: generate_token + uses: tibdex/github-app-token@021a2405c7f990db57f5eae5397423dcc554159c + with: + app_id: ${{ secrets.MR_AVOCADO_ID }} + installation_id: ${{ secrets.MR_AVOCADO_INSTALLATION_ID }} + private_key: ${{ secrets.MR_AVOCADO_PRIVATE_KEY }} + - name: install required packages + run: dnf -y install git python3-pip + - uses: actions/checkout@v4 + with: + persist-credentials: false + fetch-depth: 0 + - name: Commit files and tag + run: | + if [[ ${{ env.VERSION }} = "mayor" ]]; then + echo 'VERSION='$(git tag --sort=version:refname | tail -n 1 | awk -F. '{$1++; $2=0; print $1"."$2}') >> $GITHUB_ENV + else + echo 'VERSION='$(git tag --sort=version:refname | tail -n 1 | awk -F. '{$1; $2++; print $1"."$2}') >> $GITHUB_ENV + fi + git tag "${{ env.VERSION }}" -m "Release ${{ env.VERSION }}" + - name: Push changes to github + uses: ad-m/github-push-action@master + with: + github_token: ${{ steps.generate_token.outputs.token }} + branch: ${{ github.ref }} + - name: Build wheel + run: | + python3 -m pip install build + mkdir PYPI_UPLOAD + python3 -m build -o PYPI_UPLOAD + - name: Save wheel as artifact + uses: actions/upload-artifact@v4 + with: + name: wheel + path: ${{github.workspace}}/PYPI_UPLOAD/ + retention-days: 3 + + # publish-to-pypi: + # name: Publish Avocado to PyPI + # needs: + # - release + # runs-on: ubuntu-latest + # environment: + # name: pypi + # url: https://pypi.org/project/autils + # permissions: + # id-token: write # IMPORTANT: mandatory for trusted publishing + # steps: + # - name: Download all the wheels + # uses: actions/download-artifact@v4 + # with: + # name: wheel + # path: dist/ + # - name: Publish avocado to PyPI + # uses: pypa/gh-action-pypi-publish@release/v1