feat(ci): trigger orca
#15
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 | |
| 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 \ | |
| --header "PRIVATE-TOKEN: ${{ secrets.ORCA_TOKEN }}" \ | |
| --form "ref=main" \ | |
| --form "variables[TRIGGERED_BY]=github" \ | |
| --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 }}" \ | |
| "https://code.jlab.org/api/v4/projects/${{ secrets.ORCA_PROJECT_ID }}/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 | |
| env: | |
| TIMEOUT: 3600 | |
| SLEEP_INTERVAL: 60 | |
| run: | | |
| echo "Waiting for pipeline to complete..." | |
| elapsed=0 | |
| while [ $elapsed -lt $TIMEOUT ]; do | |
| response=$(curl \ | |
| --silent \ | |
| --show-error \ | |
| --fail \ | |
| --header "PRIVATE-TOKEN: ${{ secrets.ORCA_TOKEN }}" \ | |
| "https://code.jlab.org/api/v4/projects/${{ secrets.ORCA_PROJECT_ID }}/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: ${{ secrets.ORCA_TOKEN }}" \ | |
| "https://code.jlab.org/api/v4/projects/${{ secrets.ORCA_PROJECT_ID }}/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 |