Skip to content

Commit

Permalink
Modularize the GDIT Action
Browse files Browse the repository at this point in the history
  • Loading branch information
Mandrenkov committed Oct 27, 2023
1 parent 6ccf0c4 commit d7c6874
Showing 1 changed file with 56 additions and 29 deletions.
85 changes: 56 additions & 29 deletions generate-docker-image-tags/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,10 @@ runs:
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
- id: get-tags
- id: get-pr-number
shell: bash
if: inputs.shortcut-api-token
run: |
BRANCH=${{ steps.get-branch.outputs.branch }}
COMMIT_SHA=${GITHUB_SHA:0:7}
if [ "$BRANCH" == "main" ] || [ "$BRANCH" == "master" ]
then
TAGS="latest,$BRANCH,$COMMIT_SHA"
else
SLASHLESS_BRANCH=`echo $BRANCH | tr / -`
TAGS="${{ inputs.prefix }}.$SLASHLESS_BRANCH,${{ inputs.prefix }}.$COMMIT_SHA"
fi
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]
then
PR_NUMBER="${{ github.event.number }}"
Expand All @@ -76,24 +66,61 @@ runs:
PR_NUMBER=""
fi
# Add additional tags for each Story ID associated with this PR.
if [ ! -z "$PR_NUMBER" ] && [ ! -z "${{ inputs.shortcut-api-token }}" ]; then
url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pull/$PR_NUMBER"
ids=$(
curl --silent -X GET \
-H "Content-Type: application/json" \
-H "Shortcut-Token: ${{ inputs.shortcut-api-token }}" \
-d "{ \"page_size\": 20, \"query\": \"is:story and pr:$url\" }" \
-L "https://api.app.shortcut.com/api/v3/search" \
| jq ".stories.data[].id"
)
echo "PR number is '$PR_NUMBER'."
echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT
- id: get-story-tags
shell: bash
if: inputs.shortcut-api-token
run: |
PR_NUMBER=${{ steps.get-pr-number.outputs.pr-number }}
url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pull/$PR_NUMBER"
ids=$(
curl --silent -X GET \
-H "Content-Type: application/json" \
-H "Shortcut-Token: ${{ inputs.shortcut-api-token }}" \
-d "{ \"page_size\": 20, \"query\": \"is:story and pr:$url\" }" \
-L "https://api.app.shortcut.com/api/v3/search" \
| jq ".stories.data[].id"
)
TAGS=()
while read -r id; do
if [ ! -z "$id" ]; then
TAGS+=( "sc-$id" )
fi
done <<< "$ids"
echo "Story tags are '$TAGS'."
echo "tags=$TAGS" >> $GITHUB_OUTPUT
while read -r id; do
if [ ! -z "$id" ]; then
TAGS="$TAGS,sc-$id"
fi
done <<< "$ids"
- id: get-branch-tags
shell: bash
if: inputs.shortcut-api-token
run: |
BRANCH=${{ steps.get-branch.outputs.branch }}
COMMIT_SHA=${GITHUB_SHA:0:7}
if [ "$BRANCH" == "main" ] || [ "$BRANCH" == "master" ]
then
TAGS=("latest" "$BRANCH" "$COMMIT_SHA")
else
SLASHLESS_BRANCH=`echo $BRANCH | tr / -`
TAGS=("${{ inputs.prefix }}.$SLASHLESS_BRANCH" "${{ inputs.prefix }}.$COMMIT_SHA")
fi
echo "Branch tags are '$TAGS'."
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- id: get-tags
shell: bash
run: |
BRANCH_TAGS=${{ steps.get-branch-tags.outputs.branch }}
STORY_TAGS=${{ steps.get-story-tags.outputs.branch }}
TAGS=("${BRANCH_TAGS[@]}" "${STORY_TAGS[@]}")
TAGS=$(IFS=, ; echo "${TAGS[@]}")
echo "Tags are '$TAGS'."
echo "tags=$TAGS" >> $GITHUB_OUTPUT

0 comments on commit d7c6874

Please sign in to comment.