From d28379eadb297923a59f4edb65af99522165a377 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Tue, 27 Jun 2023 15:33:18 +0200 Subject: [PATCH] Change: Use new container and release workflows --- .github/workflows/container.yml | 30 ++++++++---- .github/workflows/deploy-pypi.yml | 21 +-------- .github/workflows/release-pontos-manually.yml | 28 ----------- .github/workflows/release-pontos.yml | 46 +++++++++++++++---- 4 files changed, 61 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/release-pontos-manually.yml diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index d2f8212d..0781d5a6 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -2,8 +2,12 @@ name: Container Image Builds on: push: - branches: [ main ] + branches: + - main tags: ["v*"] + pull_request: + branches: + - main workflow_dispatch: jobs: @@ -14,6 +18,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + - uses: greenbone/actions/is-latest-tag@v2 + id: latest - name: Setup container meta information id: meta uses: docker/metadata-action@v4 @@ -24,14 +30,20 @@ jobs: org.opencontainers.image.base.name=debian/bullseye-slim flavor: latest=false # no latest container tag for git tags tags: | - # create container tag for git tags - type=ref,event=tag - # use latest for stable branch - type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }} - type=raw,value=stable,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }} - type=raw,value=oldstable,enable=${{ github.ref == format('refs/heads/{0}', 'oldstable') }} - # use unstable for main branch - type=raw,value=unstable,enable={{is_default_branch}} + # use version, major.minor and major for tags + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + # use edge for default branch + type=edge + + # set label for non-published pull request builds + type=ref,event=pr + + # when a new git tag is created set stable and a latest tags + type=raw,value=latest,enable=${{ steps.latest.outputs.is-latest-tag == 'true' }} + type=raw,value=stable,enable=${{ steps.latest.outputs.is-latest-tag == 'true' }} - name: Login to GitHub Container Registry uses: docker/login-action@v2 with: diff --git a/.github/workflows/deploy-pypi.yml b/.github/workflows/deploy-pypi.yml index 5ca119da..b31d0b70 100644 --- a/.github/workflows/deploy-pypi.yml +++ b/.github/workflows/deploy-pypi.yml @@ -6,22 +6,5 @@ on: jobs: deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.8 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install --upgrade poetry - python -m pip install --upgrade twine - - name: Build and publish - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} - run: | - poetry build - twine upload dist/* + uses: greenbone/workflows/.github/workflows/deploy-pypi.yml@main + secrets: inherit diff --git a/.github/workflows/release-pontos-manually.yml b/.github/workflows/release-pontos-manually.yml deleted file mode 100644 index 3054f471..00000000 --- a/.github/workflows/release-pontos-manually.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Manually release Python package with pontos - -on: - workflow_dispatch: - inputs: - branch: - description: "Branch" - required: true - default: "main" - -jobs: - build-and-release: - name: Build and release with pontos - runs-on: "ubuntu-latest" - steps: - - name: Release with release action - uses: greenbone/actions/release@v2 - with: - version: "3.10" - conventional-commits: true - ref: ${{ github.event.inputs.branch }} - github-user: ${{ secrets.GREENBONE_BOT }} - github-user-mail: ${{ secrets.GREENBONE_BOT_MAIL }} - github-user-token: ${{ secrets.GREENBONE_BOT_TOKEN }} - gpg-key: ${{ secrets.GPG_KEY }} - gpg-fingerprint: ${{ secrets.GPG_FINGERPRINT }} - gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} - strategy: calendar diff --git a/.github/workflows/release-pontos.yml b/.github/workflows/release-pontos.yml index 597d83ce..e238fada 100644 --- a/.github/workflows/release-pontos.yml +++ b/.github/workflows/release-pontos.yml @@ -3,24 +3,54 @@ name: Release Python package with pontos on: pull_request: types: [closed] + workflow_dispatch: + inputs: + release-type: + type: choice + description: What kind of release do you want to do (pontos --release-type argument)? + options: + - patch + - minor + - major + release-version: + type: string + description: Set an explicit version, that will overwrite release-type. Fails if version is not compliant. + jobs: build-and-release: - name: Build and release with pontos - # If the label 'make release' is set. If PR is closed because of an merge - if: contains( github.event.pull_request.labels.*.name, 'make release') && github.event.pull_request.merged == true - runs-on: "ubuntu-latest" + name: Create a new release + # If the event is a workflow_dispatch or on of the labels 'pre release', + # 'patch release', 'minor release' or 'major release' is set and PR is + # closed because of a merge + # NOTE: priority of set labes will be alpha > release-candidate > patch > minor > major, + # so if 'major' and 'patch' labes are set, it will create a patch release. + if: | + ( github.event_name == 'workflow_dispatch') || ( + ( contains(github.event.pull_request.labels.*.name, 'alpha release') || + contains(github.event.pull_request.labels.*.name, 'rc release') || + contains(github.event.pull_request.labels.*.name, 'patch release') || + contains(github.event.pull_request.labels.*.name, 'minor release') || + contains(github.event.pull_request.labels.*.name, 'major release')) && + github.event.pull_request.merged == true ) + runs-on: 'ubuntu-latest' steps: + - name: Selecting the Release type + id: release-type + uses: greenbone/actions/release-type@v2 + with: + release-type-input: ${{ inputs.release-type }} - name: Release with release action uses: greenbone/actions/release@v2 with: - version: "3.10" - conventional-commits: true - ref: ${{ github.ref_name }} + python-version: "3.10" github-user: ${{ secrets.GREENBONE_BOT }} github-user-mail: ${{ secrets.GREENBONE_BOT_MAIL }} github-user-token: ${{ secrets.GREENBONE_BOT_TOKEN }} gpg-key: ${{ secrets.GPG_KEY }} gpg-fingerprint: ${{ secrets.GPG_FINGERPRINT }} gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} - strategy: calendar + release-type: ${{ steps.release-type.outputs.release-type }} + release-version: ${{ inputs.release-version }} + ref: ${{ steps.release-type.outputs.release-ref }} + versioning-scheme: "semver"