-
Notifications
You must be signed in to change notification settings - Fork 21
86 lines (83 loc) · 3.29 KB
/
trigger.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
name: PR comments to trigger gitlab-ci jobs
on:
pull_request_review_comment:
types:
- created
issue_comment:
types:
- created
jobs:
verify:
name: Verify Commenter
runs-on: ubuntu-22.04
steps:
- name: Standardize PR comment
id: pr-standardize-comment
uses: sarcasticadmin/action-standardize-pr-comment@bc2d905e9d53bcdd31dc224e91a44362bd25ae8d
- name: 'Collect event data'
# Currently limiting this to robs user til stable
if: >
startsWith(steps.pr-standardize-comment.outputs.comment, '/tux')
&& github.actor == 'sarcasticadmin'
id: job
run: |
set -eux
SUBCOMM=$(cut -d ' ' -f 2 <<< "${{ steps.pr-standardize-comment.outputs.comment }}")
SUBARGS="$(cut -d ' ' -f 3- <<< "${{ steps.pr-standardize-comment.outputs.comment }}")"
# Have to do this to get git commit ref for comments in PRs
# "github.event.pull_request.head" will not work since this
# is not a PR event
REF=$(curl -sSf \
--url ${{ steps.pr-standardize-comment.outputs.url }} \
--header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'Content-Type: application/json' | jq -r '.head.ref' \
)
echo ::set-output name=subcomm::$SUBCOMM
echo ::set-output name=subargs::$SUBARGS
echo ::set-output name=ref::$REF
continue-on-error: true
outputs:
subcomm: ${{ steps.job.outputs.subcomm }}
subargs: ${{ steps.job.outputs.subargs }}
ref: ${{ steps.job.outputs.ref }}
issue_number: ${{ steps.pr-standardize-comment.outputs.issue_number }}
flash:
name: Flash netgear hardware
runs-on: ubuntu-22.04
needs: verify
if: >
needs.verify.outputs.subcomm == 'openwrt'
&& startsWith(needs.verify.outputs.subargs, 'flash')
steps:
# secret required is a gitlab trigger token
# ref: https://docs.gitlab.com/ee/ci/triggers/#create-a-trigger-token
- name: 'call gitlab pipeline'
id: flash
run: |
set -euo pipefail
WORMHOLE_CODE=$(cut -d ' ' -f 2 <<< "${{ needs.verify.outputs.subargs }}")
PIPELINE=$(curl -f --request POST \
--form token=${{ secrets.GITLAB_TOKEN }} \
--form "ref=${{ needs.verify.outputs.ref }}" \
--form "variables[OPENWRT_INTEG]=YES" \
--form variables[WORMHOLE_CODE]=$WORMHOLE_CODE \
https://gitlab.com/api/v4/projects/17362342/trigger/pipeline | jq -r .web_url)
echo ::set-output name=pipeline::$PIPELINE
- name: Create status PR Comment
if: ${{ success() }}
uses: peter-evans/create-or-update-comment@ca08ebd5dc95aa0cd97021e9708fcd6b87138c9b # SHA ref: v3.0.1
with:
issue-number: ${{ needs.verify.outputs.issue_number }}
body: |
[RUNNING] - Successfully triggered gitlab flash pipeline:
- gitlab pipeline: ${{ steps.flash.outputs.pipeline }}
- name: Create status PR comment failure
if: ${{ failure() }}
uses: peter-evans/create-or-update-comment@ca08ebd5dc95aa0cd97021e9708fcd6b87138c9b # SHA ref: v3.0.1
with:
issue-number: ${{ needs.verify.outputs.issue_number }}
body: |
[FAIL] - Error triggering gitlab flash pipeline
outputs:
pipeline: ${{ steps.flash.outputs.pipeline }}