Skip to content

Commit

Permalink
Refactor validation jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelmag110 committed Sep 18, 2024
1 parent e7d680d commit 1143ce7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 45 deletions.
44 changes: 23 additions & 21 deletions .github/workflows/draft-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }})
Expand All @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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/[email protected]
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 }}
Expand Down
41 changes: 17 additions & 24 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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' }}

Expand All @@ -136,19 +129,19 @@ 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
publish-openapi-to-gh-pages:
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 }}

0 comments on commit 1143ce7

Please sign in to comment.