diff --git a/.github/workflows/README.md b/.github/workflows/README.md index f44c819b..dd3c8cbd 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -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 @@ -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. diff --git a/.github/workflows/trigger-gitlab-pipeline.yml b/.github/workflows/trigger-gitlab-pipeline.yml index a88c1edc..8807cddb 100644 --- a/.github/workflows/trigger-gitlab-pipeline.yml +++ b/.github/workflows/trigger-gitlab-pipeline.yml @@ -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"