feat(ci): trigger orca
#24
Workflow file for this run
This file contains hidden or 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
| name: orca | |
| on: | |
| pull_request: | |
| push: | |
| branches: [ development ] | |
| tags: [ '*' ] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
| cancel-in-progress: true | |
| defaults: | |
| run: | |
| shell: bash | |
| env: | |
| ORCA_ENDPOINT: https://code.jlab.org/api/v4/projects/${{ secrets.ORCA_PROJECT_ID }} | |
| ORCA_PROJECT_TOKEN: ${{ secrets.ORCA_PROJECT_TOKEN }} | |
| ORCA_TRIGGER_TOKEN: ${{ secrets.ORCA_TRIGGER_TOKEN }} | |
| TIMEOUT: 3600 # how long to wait overall [s] | |
| SLEEP_INTERVAL: 60 # duration between each pipeline-status check [s] | |
| jobs: | |
| orca_trigger: | |
| name: Trigger | |
| runs-on: ubuntu-latest | |
| outputs: | |
| pipeline_id: ${{ steps.trigger.outputs.pipeline_id }} | |
| pipeline_url: ${{ steps.trigger.outputs.web_url }} | |
| steps: | |
| - name: trigger orca pipeline | |
| id: trigger | |
| run: | | |
| response=$(curl \ | |
| --silent --show-error --fail \ | |
| --request POST \ | |
| --form "token=$ORCA_TRIGGER_TOKEN" \ | |
| --form "ref=main" \ | |
| --form "variables[TRIGGERED_BY]=github" \ | |
| --form "variables[GITHUB_EVENT]=${{ github.event_name }}" \ | |
| --form "variables[GITHUB_REPO]=${{ github.repository }}" \ | |
| --form "variables[GITHUB_SHA]=${{ github.sha }}" \ | |
| --form "variables[GITHUB_RUN_ID]=${{ github.run_id }}" \ | |
| --form "variables[REF_COATJAVA]=${{ github.head_ref || github.ref_name }}" \ | |
| "$ORCA_ENDPOINT/trigger/pipeline") | |
| echo "RESPONSE: $response" | |
| pipeline_id=$(echo $response | jq -r '.id') | |
| web_url=$(echo $response | jq -r '.web_url') | |
| if [ "$pipeline_id" == "null" ] || [ -z "$pipeline_id" ]; then | |
| echo "ERROR: Failed to trigger pipeline" >&2 | |
| exit 1 | |
| fi | |
| echo "pipeline_id=$pipeline_id" >> $GITHUB_OUTPUT | |
| echo "web_url=$web_url" >> $GITHUB_OUTPUT | |
| echo "Pipeline triggered successfully!" | |
| echo "Pipeline URL: $web_url" | |
| echo "Orca Pipeline URL: <$web_url>" >> $GITHUB_STEP_SUMMARY | |
| orca_wait: | |
| name: Wait | |
| runs-on: ubuntu-latest | |
| needs: | |
| - orca_trigger | |
| steps: | |
| - name: wait for orca pipeline | |
| run: | | |
| echo "Waiting for pipeline to complete ... checking every $TIMEOUT s ..." | |
| elapsed=0 | |
| while [ $elapsed -lt $TIMEOUT ]; do | |
| response=$(curl \ | |
| --silent --show-error --fail \ | |
| --header "PRIVATE-TOKEN: $ORCA_PROJECT_TOKEN" \ | |
| "$ORCA_ENDPOINT/pipelines/${{ needs.orca_trigger.outputs.pipeline_id }}") | |
| status=$(echo $response | jq -r '.status') | |
| echo "Current status: $status (elapsed: ${elapsed}s)" | |
| case $status in | |
| "success") | |
| echo "Pipeline completed successfully!" | |
| exit 0 | |
| ;; | |
| "failed") | |
| echo "Pipeline failed!" | |
| exit 1 | |
| ;; | |
| "canceled") | |
| echo "Pipeline was canceled!" | |
| exit 1 | |
| ;; | |
| "skipped") | |
| echo "Pipeline was skipped!" | |
| exit 1 | |
| ;; | |
| "running"|"pending"|"created") | |
| echo "Pipeline is still running..." | |
| sleep $SLEEP_INTERVAL | |
| elapsed=$((elapsed + SLEEP_INTERVAL)) | |
| ;; | |
| *) | |
| echo "Unknown status: $status" | |
| sleep $SLEEP_INTERVAL | |
| elapsed=$((elapsed + SLEEP_INTERVAL)) | |
| ;; | |
| esac | |
| done | |
| echo "Timeout waiting for pipeline to complete" | |
| exit 1 | |
| - name: cancel pipeline if caller is cancelled | |
| if: cancelled() && needs.orca_trigger.outputs.pipeline_id | |
| run: | | |
| echo "GitHub workflow was cancelled, cancelling orca pipeline..." | |
| response=$(curl \ | |
| --silent --show-error --fail \ | |
| --write-out "\n%{http_code}" \ | |
| --request POST \ | |
| --header "PRIVATE-TOKEN: $ORCA_PROJECT_TOKEN" \ | |
| "$ORCA_ENDPOINT/pipelines/${{ needs.orca_trigger.outputs.pipeline_id }}/cancel") | |
| http_code=$(echo "$response" | tail -n1) | |
| response_body=$(echo "$response" | sed '$d') | |
| if [ "$http_code" -eq 200 ] || [ "$http_code" -eq 201 ]; then | |
| echo "GitLab pipeline cancelled successfully" | |
| else | |
| echo "Failed to cancel GitLab pipeline (HTTP $http_code)" | |
| echo "Response: $response_body" | |
| exit 1 | |
| fi |