Skip to content

Commit

Permalink
[MOL-14987][BC] Update gitlab action
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedict committed Mar 8, 2024
1 parent 66ce2bd commit 14a37aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ We have set variables in the settings of the GitHub repository that is needed to

These variables are:

- GITLAB_TOKEN - The token created in GitLab to authenticate the use of the API
- GITLAB_PAT - The personal access token by the gitlab user (currently no organisation pat)
- GITLAB_TOKEN - The gitlab pipeline trigger token created in GitLab to authenticate the use of the API ([instruction](https://docs.gitlab.com/ee/ci/triggers/#create-a-pipeline-trigger-token))
- GITLAB_ENDPOINT - The host domain of GitLab
- GITLAB_PROJECT_ID - The project ID of the GitLab pipeline that builds the lib
- GITLAB_REPO_NAME - The name of the repository being built
Expand All @@ -39,3 +40,5 @@ The API contains variables that are important to be passed in the body of the re
- PIPELINE_COMMIT_MSG - the 1st line of the commit message

Then the Project in GitLab responsible for running the pipeline will create and start the pipeline.

The GitHub action is marked as successful when the GitLab pipeline's `build-dist-job` is successful. After that you are able to deploy to storybook/github/npm.
26 changes: 17 additions & 9 deletions .github/workflows/trigger-gitlab-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,33 @@ jobs:
GITLAB_PROJECT_ID: ${{ vars.GITLAB_PROJECT_ID }}
SLEEP_DURATION_MINUTES: 15
CHECK_INTERVAL_MINUTES: 5
DOWNSTREAM_PIPELINE_NAME: library
DOWNSTREAM_JOB_NAME: build-dist-job
run: |
echo "Pipeline ID: $PIPELINE_ID"
echo "[ Running pipline check after $SLEEP_DURATION_MINUTES minutes ]"
sleep $(($SLEEP_DURATION_MINUTES*60))
pipeline_status=""
until [[ $pipeline_status == "success" || $pipeline_status == "failed" || $pipeline_status == "canceled" || $pipeline_status == "skipped" ]]
job_status=""
until [[ $job_status == "success" || $job_status == "failed" || $job_status == "canceled" || $job_status == "skipped" ]]
do
pipeline_status=$(curl -sS --request GET --header "PRIVATE-TOKEN: $GITLAB_PAT" --url "$GITLAB_ENDPOINT/$GITLAB_PROJECT_ID/pipelines/$PIPELINE_ID" | jq -r '.status')
echo "Pipeline status: $pipeline_status"
downstream_pipeline_id=$(curl -sS --request GET --header "PRIVATE-TOKEN: $GITLAB_PAT" \
--url "$GITLAB_ENDPOINT/$GITLAB_PROJECT_ID/pipelines/$PIPELINE_ID/bridges" \
| jq -r '[ .[] | select( .name | contains("'"$DOWNSTREAM_PIPELINE_NAME"'")) ]' | jq -r '.[].downstream_pipeline.id')
echo "($DOWNSTREAM_PIPELINE_NAME) Downstream pipeline id: $downstream_pipeline_id"
job_status=$(curl -sS --header "PRIVATE-TOKEN: $GITLAB_PAT" \
--url "$GITLAB_ENDPOINT/$GITLAB_PROJECT_ID/pipelines/$downstream_pipeline_id/jobs" \
| jq -r '[ .[] | select( .name | contains("'"$DOWNSTREAM_JOB_NAME"'")) ]' | jq -r '.[].status')
echo "($DOWNSTREAM_JOB_NAME) Job status: $job_status"
sleep $(($CHECK_INTERVAL_MINUTES*60))
done
[[ $pipeline_status == "canceled" ]] && echo "GitLab Pipeline was cancelled"
[[ $job_status == "canceled" ]] && echo "GitLab job was cancelled"
[[ $pipeline_status == "skipped" ]] && echo "GitLab pipeline has stopped, please head to the GitLab pipeline to trigger job manually"
[[ $job_status == "skipped" ]] && echo "GitLab job has stopped, please head to the GitLab job to trigger job manually"
[[ $pipeline_status == "failed" ]] && echo "GitLab pipeline has failed, please head to the GitLab pipeline to check on error" && exit 1
[[ $job_status == "failed" ]] && echo "GitLab job has failed, please head to the GitLab job to check on error" && exit 1
[[ $pipeline_status == "success" ]] && echo "GitLab pipeline is successfully completed, please head to the GitLab pipeline for further deployments"
[[ $job_status == "success" ]] && echo "GitLab job is successfully completed, please head to the GitLab job for further deployments"

0 comments on commit 14a37aa

Please sign in to comment.