From 366ca72f9a689096c4ae8a9c798fdd694abed902 Mon Sep 17 00:00:00 2001 From: Paul Latzelsperger Date: Thu, 13 Jun 2024 12:23:03 +0200 Subject: [PATCH] feat: add parameter for the target branch --- .github/workflows/publish-all-in-one.yaml | 10 ++++++++ .github/workflows/release.yaml | 29 ++++++++++++++++++----- scripts/github_action.sh | 12 +++++++--- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/.github/workflows/publish-all-in-one.yaml b/.github/workflows/publish-all-in-one.yaml index 5cee0c9..568599f 100644 --- a/.github/workflows/publish-all-in-one.yaml +++ b/.github/workflows/publish-all-in-one.yaml @@ -7,12 +7,22 @@ on: type: string required: true description: "The version that should be released. " + branch: + type: string + required: false + default: "main" + description: "The branch which to publish. must exist in all repos!" workflow_call: inputs: version: type: string required: true description: "The version that should be released. " + branch: + type: string + required: false + default: "main" + description: "The branch which to publish. must exist in all repos!" env: VERSION: ${{ github.event.inputs.version || inputs.version }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 001d2dd..67acc93 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -5,9 +5,14 @@ on: version: description: Semantic Version string to use for this release required: true + branch: + description: Source ranch from which the version should be created. If omitted, 'main' is used. + required: false + default: "main" env: INPUT_VERSION: ${{ github.event.inputs.version || inputs.version }} + INPUT_SOURCE_BRANCH: ${{ github.event.inputs.branch || inputs.branch }} concurrency: @@ -41,6 +46,16 @@ jobs: id: get-version run: echo "VERSION=${{ env.INPUT_VERSION }}" >> "$GITHUB_OUTPUT" + Determine-Branch: + # this looks to be necessary because some constructs as "with" are not able to get values from env + runs-on: ubuntu-latest + outputs: + SOURCE_BRANCH: ${{ steps.get-branch.outputs.BRANCH }} + steps: + - name: "Get branch" + id: get-branch + run: echo "SOURCE_BRANCH=${{ env.INPUT_SOURCE_BRANCH }}" >> "$GITHUB_OUTPUT" + Run-All-Tests: name: "Run tests" runs-on: ubuntu-latest @@ -61,21 +76,23 @@ jobs: - name: "Run test for ${{ matrix.test-def.repo }}" run: | chmod +x ./scripts/github_action.sh - ./scripts/github_action.sh "eclipse-edc" "${{ matrix.test-def.repo }}" "${{ matrix.test-def.workflowfile}}" "" "${{ secrets.ORG_GITHUB_BOT_USER }}" "${{ secrets.ORG_GITHUB_BOT_TOKEN }}" + ./scripts/github_action.sh "eclipse-edc" "${{ matrix.test-def.repo }}" "${{ matrix.test-def.workflowfile}}" "" "${{ secrets.ORG_GITHUB_BOT_USER }}" "${{ secrets.ORG_GITHUB_BOT_TOKEN }}" "${{ env.INPUT_SOURCE_BRANCH }}" Publish-Components: - needs: [ Determine-Version, Run-All-Tests ] - uses: eclipse-edc/Release/.github/workflows/publish-all-in-one.yaml@main + needs: [ Determine-Version, Determine-Branch, Run-All-Tests ] + uses: ./.github/workflows/publish-all-in-one.yaml with: version: ${{ needs.Determine-Version.outputs.VERSION }} + branch: "${{ needs.Determine-Branch.outputs.SOURCE_BRANCH }}" secrets: inherit Release-Components: name: "Release Components" runs-on: ubuntu-latest - needs: [ Determine-Version, Publish-Components ] + needs: [Secrets-Presence, Determine-Version, Determine-Branch, Publish-Components ] if: | - needs.Secrets-Presence.outputs.HAS_GH_PAT + needs.Secrets-Presence.outputs.HAS_GH_PAT && + needs.Determine-Branch.outputs.SOURCE_BRANCH == 'main' strategy: fail-fast: false max-parallel: 1 @@ -103,7 +120,7 @@ jobs: Post-To-Discord: needs: [ Publish-Components, Release-Components, Determine-Version, Secrets-Presence ] - if: "needs.Secrets-Presence.outputs.HAS_WEBHOOK && always()" + if: needs.Secrets-Presence.outputs.HAS_WEBHOOK && always() runs-on: ubuntu-latest steps: - uses: sarisia/actions-status-discord@v1 diff --git a/scripts/github_action.sh b/scripts/github_action.sh index 38c4fdd..883544f 100755 --- a/scripts/github_action.sh +++ b/scripts/github_action.sh @@ -6,13 +6,14 @@ WORKFLOW="$3" INPUTS="$4" USER="$5" PWD="$6" +BRANCH="$7" if [ "$#" -eq 5 ]; then # use cURL with a Personal Access Token echo "Using USER as personal access token for the GitHub API" PARAMS=(-H "Authorization: Bearer $USER" -H "Accept: application/vnd.github.v3+json") -elif [ "$#" -eq 6 ]; then +elif [ "$#" -ge 6 ]; then # use basic auth with cUrl echo "Using USER/PWD authentication for the GitHub API" PARAMS=(-u "$USER":"$PWD" -H "Accept: application/vnd.github.v3+json") @@ -25,17 +26,22 @@ else echo "INPUTS = json representation of the workflow input" echo "USER = the username to use for authentication against the GitHub API, or an API token" echo "PWD = the password of USER. if not specified, USER will be interpreted as token" + echo "BRANCH" = the branch on which to execute the action. Defaults to "main" exit 1 fi REPO="$OWNER/$REPO_NAME" WORKFLOW_PATH="$REPO/actions/workflows/$WORKFLOW" +# run actions on "main" by default +if [ -z "${BRANCH}" ]; then + BRANCH="main" +fi if [ -z "${INPUTS}" ]; then - TRIGGER_BODY="{\"ref\": \"main\"}" + TRIGGER_BODY="{\"ref\": \"${BRANCH}\"}" else - TRIGGER_BODY="{\"ref\": \"main\", \"inputs\": ${INPUTS}}" + TRIGGER_BODY="{\"ref\": \"${\", \"inputs\": ${INPUTS}}" fi echo "$WORKFLOW_PATH :: $(date) :: Trigger the workflow with ${TRIGGER_BODY}"