@@ -20,10 +20,14 @@ jobs:
2020 - name : Determine PR merge ref
2121 id : setref
2222 shell : bash
23+ env :
24+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
2325 run : |
2426 PR_NUMBER=${{ github.event.issue.number }}
2527 MERGE_REF="refs/pull/$PR_NUMBER/merge"
28+ PR_TITLE=$(gh api repos/${{ github.repository }}/pulls/$PR_NUMBER --jq '.title')
2629 echo "merge_ref=$MERGE_REF" >> $GITHUB_OUTPUT
30+ echo "pr_title=$PR_TITLE" >> $GITHUB_OUTPUT
2731 echo "Using merge ref: $MERGE_REF"
2832
2933 - name : Trigger GitLab pipeline
3943 -F "variables[GITHUB_PR_NUMBER]=${{ github.event.issue.number }}" \
4044 -F "variables[GITHUB_MERGE_REF]=refs/pull/${{ github.event.issue.number }}/merge" \
4145 -F "variables[GITHUB_TRIGGER_ACTOR]=${{ github.actor }}" \
46+ -F "variables[GITHUB_PR_TITLE]=${{ steps.setref.outputs.pr_title }}" \
4247 "https://gitlab.spack.io/api/v4/projects/${{ env.GITLAB_PROJECT_ID }}/trigger/pipeline")
4348
4449 echo "GitLab response: $RESPONSE"
5055 exit 1
5156 fi
5257
53- echo "Pipeline URL: https://gitlab.spack.io/${{ env.GITLAB_PROJECT_PATH }}/-/pipelines/$PIPELINE_ID"
58+ PIPELINE_URL="https://gitlab.spack.io/${{ env.GITLAB_PROJECT_PATH }}/-/pipelines/$PIPELINE_ID"
59+ echo "Pipeline URL: $PIPELINE_URL"
60+ echo "pipeline_url=$PIPELINE_URL" >> $GITHUB_OUTPUT
5461 echo "pipeline_id=$PIPELINE_ID" >> $GITHUB_OUTPUT
5562
63+ # Update pipeline name
64+ PIPELINE_NAME="GitHub #${{ github.event.issue.number }}: ${{ steps.setref.outputs.pr_title }}"
65+ curl --request PUT \
66+ --header "PRIVATE-TOKEN: ${{ secrets.HPSF_GITLAB_API_TOKEN }}" \
67+ --data-urlencode "name=${PIPELINE_NAME}" \
68+ "https://gitlab.spack.io/api/v4/projects/${{ env.GITLAB_PROJECT_ID }}/pipelines/${PIPELINE_ID}/metadata"
69+ || echo "Warning: Failed to update pipline name (possibly expired token)"
70+ echo "Updated pipeline name to: $PIPELINE_NAME"
71+
72+ - name : Post status to GitHub PR
73+ shell : bash
74+ run : |
75+ PIPELINE_URL=${{ steps.trigger.outputs.pipeline_url }}
76+ COMMENT="GitLab CI has started at ${PIPELINE_URL}."
77+
78+ gh api \
79+ repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments \
80+ -f body="$COMMENT" || echo "Failed to post comment to GitHub"
81+ env :
82+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
83+
5684 - name : Wait for GitLab pipeline to finish
5785 id : wait
5886 shell : bash
@@ -62,11 +90,29 @@ jobs:
6290 echo "Waiting on GitLab pipeline $PIPELINE_ID..."
6391
6492 STATUS="running"
93+ MAX_WAIT=14400 # 4 hours
94+ ELAPSED=0
95+
6596 while [[ "$STATUS" == "running" || "$STATUS" == "pending" ]]; do
97+ if [ $ELAPSED -ge $MAX_WAIT ]; then
98+ echo "Timeout waiting for pipeline after $MAX_WAIT seconds"
99+ echo "final_status=timeout" >> $GITHUB_OUTPUT
100+ exit 1
101+ fi
102+
66103 sleep 300
104+ ELAPSED=$((ELAPSED + 300))
105+
67106 STATUS=$(curl -s \
68107 "https://gitlab.spack.io/api/v4/projects/${{ env.GITLAB_PROJECT_ID }}/pipelines/$PIPELINE_ID" \
69108 | jq -r '.status')
109+
110+ if [ "$STATUS" == "null" ] || [ -z "$STATUS" ]; then
111+ echo "Failed to get pipeline status. Response: $RESPONSE"
112+ echo "final_status=error" >> $GITHUB_OUTPUT
113+ exit 1
114+ fi
115+
70116 echo "Status: $STATUS"
71117 done
72118
76122 shell : bash
77123 run : |
78124 STATUS=${{ steps.wait.outputs.final_status }}
79- PIPELINE_ID=${{ steps.trigger.outputs.pipeline_id }}
80- PIPELINE_URL="https://gitlab.spack.io/${{ env.GITLAB_PROJECT_PATH }}/-/pipelines/$PIPELINE_ID"
125+ PIPELINE_URL=${{ steps.trigger.outputs.pipeline_url }}
81126 COMMENT="GitLab CI finished with status: **$STATUS**. See details at ${PIPELINE_URL}."
82127
83128 gh api \
0 commit comments