Avoid failing label removal if label is not there
[openssl.git] / .github / workflows / fips-label.yml
1 name: FIPS Changed Label
2 on:
3   workflow_run:
4     workflows: ["FIPS Checksums"]
5     types:
6       - completed
7
8 jobs:
9   apply-label:
10     runs-on: ubuntu-latest
11     if: ${{ github.event.workflow_run.event == 'pull_request' }}
12     steps:
13       - name: 'Check artifact and apply'
14         if: ${{ github.event.workflow_run.conclusion == 'success' }}
15         uses: actions/github-script@v4
16         with:
17           github-token: ${{secrets.GITHUB_TOKEN}}
18           script: |
19             var artifacts = await github.actions.listWorkflowRunArtifacts({
20               owner: context.repo.owner,
21               repo: context.repo.repo,
22               run_id: ${{ github.event.workflow_run.id }},
23             });
24             if ( artifacts.data.artifacts[0].name == 'fips_changed' ) {
25               github.issues.addLabels({
26                 issue_number: ${{ github.event.workflow_run.pull_requests[0].number }},
27                 owner: context.repo.owner,
28                 repo: context.repo.repo,
29                 labels: ['severity: fips change']
30               });
31             } else if ( artifacts.data.artifacts[0].name == 'fips_unchanged' ) {
32               var labels = await github.issues.listLabelsOnIssue({
33                 issue_number: ${{ github.event.workflow_run.pull_requests[0].number }},
34                 owner: context.repo.owner,
35                 repo: context.repo.repo,
36               });
37
38               for ( var label in labels.data ) {
39                 if (labels.data[label].name == 'severity: fips change') {
40                   github.issues.removeLabel({
41                     issue_number: ${{ github.event.workflow_run.pull_requests[0].number }},
42                     owner: context.repo.owner,
43                     repo: context.repo.repo,
44                     name: 'severity: fips change'
45                   });
46                 }
47               }
48             }