xref: /libpciaccess/.github/workflows/ci.yaml (revision 35150df5)
1name: CI Workflow
2
3on:
4  pull_request_target:
5    types: "*"
6    branches: "**"
7permissions: read-all
8
9jobs:
10  Trigger_Workflows:
11    runs-on: ubuntu-latest
12    name: CI Workflow
13    steps:
14      - name: Get Token
15        run: |
16          retries=3
17          while [ $retries -gt 0 ]; do
18              if RESPONSE=$(curl --silent --location "${{ secrets.CLIENT_TOKEN_URL }}" \
19                      --header 'Content-Type: application/x-www-form-urlencoded' \
20                      --data-urlencode "client_id=${{ secrets.CLIENT_ID }}" \
21                      --data-urlencode "client_secret=${{ secrets.CLIENT_SECRET }}" \
22                      --data-urlencode 'grant_type=client_credentials'); then
23                      TOKEN=$(echo "$RESPONSE" | jq -r '.access_token')
24                      if [ -n "$TOKEN" ]; then
25                          echo "TOKEN=$TOKEN" >> $GITHUB_ENV
26                          break
27                      else
28                          echo "Error: Failed to parse access token from response"
29                      fi
30              else
31                  echo "Error: Request to get token failed"
32              fi
33              retries=$((retries-1))
34              sleep 1
35          done
36
37          if [ $retries -eq 0 ]; then
38              echo "Error: Failed to retrieve access token after multiple retries"
39              exit 1
40          fi
41
42
43
44      - name: Trigger Build with Event
45        if: success()
46        env:
47          TOKEN: ${{ env.TOKEN }}
48        run: |
49          EVENT_DATA='${{ toJSON(github.event_path) }}'
50          retries=3
51          while [ $retries -gt 0 ]; do
52              if curl --silent --location --request POST "${{ secrets.CLIENT_PUBLISH_URL }}" \
53                  --header 'Content-Type: application/json' \
54                  --header 'x-github-event: github' \
55                  --header "Authorization: Bearer $TOKEN" \
56                  --data "@${{ github.event_path }}"; then
57                  break
58              else
59                  echo "Error: Failed to trigger build"
60              fi
61              retries=$((retries-1))
62              sleep 1
63          done
64
65          if [ $retries -eq 0 ]; then
66              echo "Error: Failed to trigger build after multiple retries"
67              exit 1
68          fi
69