-
Notifications
You must be signed in to change notification settings - Fork 3
52 lines (50 loc) · 1.88 KB
/
slash-build-command.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
name: Slash Build Command
on:
issue_comment:
types: [created]
jobs:
comment_created_by_maintainer:
if: ${{ contains(github.event.comment.body, '/build') && github.actor == 'tanmoysrt' }}
permissions:
actions: write
issues: write
runs-on: ubuntu-latest
steps:
- name: Check args
id: check-args
run: |
IFS=' ' read -r -a args <<< "${{ github.event.comment.body }}"
if [ ${#args[@]} -ne 3 ]; then
echo "Invalid number of arguments. Usage: $0 \"/build <app_name> <version>\""
exit 1
fi
app_name="${args[1]}"
version="${args[2]}"
if [ -z "$app_name" ] || [ -z "$version" ]; then
echo "App name or version is blank."
exit 1
fi
echo "APP_NAME=$app_name" >> $GITHUB_ENV
echo "VERSION=$version" >> $GITHUB_ENV
echo "Parsed arguments: App Name: $app_name, Version: $version"
- name: Trigger build
id: trigger-build
run: |
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/build-image.yml/dispatches \
-d '{"ref":"main", "inputs":{"app_name":"${{ env.APP_NAME }}", "version": "${{ env.VERSION }}"}}'
- name: Add reaction +1
id: add-reaction
if: ${{ steps.trigger-build.outcome }} == 'success'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ github.event.comment.id }}
reactions: "+1"
- name: Add reaction -1
id: add-reaction
if: ${{ steps.trigger-build.outcome }} == 'failure'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ github.event.comment.id }}
reactions: "-1"