-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: calculate branch reusable workflow
- Loading branch information
1 parent
5e74350
commit 6fea63a
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: Calculate Branch | ||
on: | ||
workflow_call: | ||
inputs: | ||
branch: | ||
description: The branch name | ||
required: true | ||
type: string | ||
repo: | ||
description: The GitHub repository name | ||
required: true | ||
type: string | ||
outputs: | ||
branch: ${{ steps.calculate_branch.outputs.branch }} | ||
found: ${{ steps.calculate_branch.outputs.found }} | ||
sha: ${{ steps.calculate_branch.outputs.sha }} | ||
sha_short: ${{ steps.calculate_branch.outputs.sha_short }} | ||
secrets: | ||
github_token: | ||
required: true | ||
|
||
jobs: | ||
calculate-branch: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Calculate Branch | ||
id: calculate_branch | ||
env: | ||
GH_TOKEN: ${{ secrets.github_token }} | ||
run: | | ||
requested_branch="${{ inputs.branch }}" | ||
repo="${{ inputs.repo }}" | ||
branch_name= | ||
found= | ||
echo "Checking to see if the branch \"${requested_branch}\" exists in this project." | ||
branch_info=$(gh api "/repos/encodium/${repo}/branches/$requested_branch" --jq '{name: .name, sha: .commit.sha}') | ||
branch_name_candidate=$(echo "$branch_info" | jq -r '.name') | ||
sha=$(echo "$branch_info" | jq -r '.sha') | ||
sha_short=$(echo "$branch_info" | jq -r '.sha[:7]') | ||
echo "Branch name from response: ${branch_name_candidate}" | ||
echo "SHA from response: ${sha}" | ||
echo "SHA (short) from response: ${sha_short}" | ||
if [[ "$branch_name_candidate" == "$requested_branch" ]]; | ||
then | ||
echo "Branch \"${branch_name_candidate}\" found." | ||
branch_name="$branch_name_candidate" | ||
found=true | ||
fi | ||
echo "branch=$branch_name" >> "$GITHUB_OUTPUT" | ||
echo "found=$found" >> "$GITHUB_OUTPUT" | ||
echo "sha=$sha" >> "$GITHUB_OUTPUT" | ||
echo "sha_short=$sha_short" >> "$GITHUB_OUTPUT" |