Skip to content

Commit

Permalink
feat: add parameter for the target branch
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Jun 13, 2024
1 parent 273eea2 commit 13f4409
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/publish-all-in-one.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
29 changes: 23 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions scripts/github_action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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\": \"${BRANCH}\", \"inputs\": ${INPUTS}}"
fi

echo "$WORKFLOW_PATH :: $(date) :: Trigger the workflow with ${TRIGGER_BODY}"
Expand Down

0 comments on commit 13f4409

Please sign in to comment.