From 1143ce7494065172cb840ed9dc5209052f772b28 Mon Sep 17 00:00:00 2001 From: Rafael Magalhaes Date: Mon, 16 Sep 2024 14:01:54 +0100 Subject: [PATCH] Refactor validation jobs --- .github/workflows/draft-release.yaml | 44 +++++++++++++++------------- .github/workflows/release.yml | 41 +++++++++++--------------- 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/.github/workflows/draft-release.yaml b/.github/workflows/draft-release.yaml index c3b306a35..3cdf9e1d0 100644 --- a/.github/workflows/draft-release.yaml +++ b/.github/workflows/draft-release.yaml @@ -31,16 +31,18 @@ on: required: true jobs: - validate-release: - name: "Validates that tag does not already exist" + validate-and-prepare: + name: "Validate that tag does not already exist and prepare branch" runs-on: ubuntu-latest if: ${{ github.ref_name == 'main' || startsWith(github.ref, 'refs/tags/') }} + outputs: + branch_name: ${{ steps.resolve_branch.outputs.branch_name }} steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - id: check-tag - name: Check if tag exists + name: "Check if tag exists" run: |- tag=$(git tag -l ${{ inputs.version }}) @@ -50,25 +52,25 @@ jobs: echo "Tag already exists! Please choose another tag." exit 1 fi - - resolve-branch-prefix: - name: "Resolve branch prefix (release or bugfix)" - needs: validate-release - runs-on: ubuntu-latest - outputs: - branch_name: ${{ steps.release.outputs.branch_name || steps.bugfix.outputs.branch_name }} - steps: - - id: release - if: github.ref_name == 'main' - run: echo "branch_name=release/${{ inputs.version }}" >> "$GITHUB_OUTPUT" - - id: bugfix - if: startsWith(github.ref, 'refs/tags/') - run: echo "branch_name=bugfix/${{ inputs.version }}" >> "$GITHUB_OUTPUT" + - id: resolve_branch + name: "Resolve branch prefix (release or bugfix)" + run: | + + if [[ ${{ github.ref_name }} == "main"]]; + then + echo "branch_name=release/${{ inputs.version }}" >> "$GITHUB_OUTPUT" + elif [[ ${{ github.ref }} == refs/tags/* ]] + then + echo "branch_name=bugfix/${{ inputs.version }}" >> "$GITHUB_OUTPUT" + else + echo "Ref branch does not match required criteria. Should either be "main" or a tag." + exit 1 + fi draft-new-release: name: "Draft a new release" runs-on: ubuntu-latest - needs: resolve-branch-prefix + needs: validate-and-prepare permissions: contents: write packages: write @@ -77,7 +79,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Create Release or Bugfix branch - run: git checkout -b ${{ needs.resolve-branch-prefix.outputs.branch_name }} + run: git checkout -b ${{ needs.validate-and-prepare.outputs.branch_name }} - name: Initialize mandatory git config run: | git config user.name "eclipse-tractusx-bot" @@ -112,14 +114,14 @@ jobs: echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - name: Push new branch - run: git push origin ${{ needs.resolve-branch-prefix.outputs.branch_name }} + run: git push origin ${{ needs.validate-and-prepare.outputs.branch_name }} - name: Create pull request if: ${{ github.ref_name == 'main' }} uses: thomaseizinger/create-pull-request@1.4.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - head: ${{ needs.resolve-branch-prefix.outputs.branch_name }} + head: ${{ needs.validate-and-prepare.outputs.branch_name }} base: main title: Release version ${{ inputs.version }} reviewers: ${{ github.actor }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 464ed5e2c..37fff07c7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,17 +34,10 @@ on: jobs: # Gate - check-head: + validation: name: "Check if repository is not fork AND head is release OR base is bugfix" runs-on: ubuntu-latest if: ${{ github.repository == 'eclipse-tractusx/tractusx-edc' && (startsWith(github.ref_name, 'bugfix/') || startsWith(github.event.pull_request.head.ref, 'release/')) }} - steps: - - run: echo "Triggering release" - - release-version: - needs: check-head - name: Determine release version - runs-on: ubuntu-latest outputs: RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }} steps: @@ -58,35 +51,35 @@ jobs: # Release: Maven Artifacts maven-release: name: Publish extension's release version to maven repository - needs: [ release-version ] + needs: [ validation ] permissions: contents: read - if: needs.release-version.outputs.RELEASE_VERSION + if: needs.validation.outputs.RELEASE_VERSION uses: ./.github/workflows/trigger-maven-publish.yaml secrets: inherit with: - version: ${{ needs.release-version.outputs.RELEASE_VERSION }} + version: ${{ needs.validation.outputs.RELEASE_VERSION }} # Release: docker images docker-release: name: Publish Docker images - needs: [ release-version ] - if: needs.release-version.outputs.RELEASE_VERSION + needs: [ validation ] + if: needs.validation.outputs.RELEASE_VERSION uses: ./.github/workflows/trigger-docker-publish.yaml secrets: inherit with: - docker_tag: ${{ needs.release-version.outputs.RELEASE_VERSION }} + docker_tag: ${{ needs.validation.outputs.RELEASE_VERSION }} # Release: Helm charts helm-release: name: Publish helm charts - needs: [ release-version ] + needs: [ validation ] runs-on: ubuntu-latest permissions: contents: write pages: write - if: needs.release-version.outputs.RELEASE_VERSION + if: needs.validation.outputs.RELEASE_VERSION steps: - uses: actions/checkout@v4 with: @@ -112,22 +105,22 @@ jobs: # Commit and push to gh-pages git add index.yaml helm-charts - git commit -s -m "Release ${{ needs.release-version.outputs.RELEASE_VERSION }}" + git commit -s -m "Release ${{ needs.validation.outputs.RELEASE_VERSION }}" git push origin gh-pages # Release: GitHub tag & release; Starts a new development cycle if latest release; github-release: name: Publish new github release - needs: [ release-version, maven-release, docker-release, helm-release ] + needs: [ validation, maven-release, docker-release, helm-release ] runs-on: ubuntu-latest permissions: contents: write - if: needs.release-version.outputs.RELEASE_VERSION + if: needs.validation.outputs.RELEASE_VERSION steps: - uses: ./.github/actions/publish-tag-and-release with: - version: ${{ needs.release-version.outputs.RELEASE_VERSION }} + version: ${{ needs.validation.outputs.RELEASE_VERSION }} token: ${{ secrets.GITHUB_TOKEN }} is_latest: ${{ github.ref_name == 'main' }} @@ -136,10 +129,10 @@ jobs: name: "Publish OpenAPI spec to Swaggerhub" permissions: contents: read - needs: [ release-version ] + needs: [ validation ] uses: ./.github/workflows/publish-swaggerhub.yaml with: - downstream-version: ${{ needs.release-version.outputs.RELEASE_VERSION }} + downstream-version: ${{ needs.validation.outputs.RELEASE_VERSION }} secrets: inherit # Release: Publish specs to GitHub Pages @@ -147,8 +140,8 @@ jobs: name: "Publish OpenAPI UI spec GitHub Pages" permissions: contents: write - needs: [ release-version ] + needs: [ validation ] uses: ./.github/workflows/publish-openapi-ui.yml secrets: inherit with: - version: ${{ needs.release-version.outputs.RELEASE_VERSION }} + version: ${{ needs.validation.outputs.RELEASE_VERSION }}