-
Notifications
You must be signed in to change notification settings - Fork 2.4k
101 lines (93 loc) · 3.77 KB
/
docker-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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: "/docker command"
on:
repository_dispatch:
types: [ docker-command ]
concurrency:
group: ${{ github.workflow }}-${{ github.event.client_payload.github.payload.issue.number }}-${{ github.event.client_payload.slash_command.command }}-${{ github.event.client_payload.slash_command.args.unnamed.arg1 || github.event.client_payload.slash_command.args.all }}
jobs:
create:
if: ${{ github.event.client_payload.slash_command.args.unnamed.arg1 == 'build' }}
runs-on: ubuntu-latest
timeout-minutes: 3
outputs:
error-msg: ${{ steps.check-membership.outputs.error }}
steps:
- uses: hmarr/[email protected]
- name: Check user's membership
uses: actions/github-script@v7
id: check-membership
env:
ACTOR: ${{ github.actor }}
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
const { repo, owner } = context.repo;
const actor = process.env.ACTOR;
const { data: membership } = await github.rest.orgs.getMembershipForUser({
org: owner,
username: actor,
});
if (membership.state != "active") {
const error = `Unfortunately you don't have membership in ${owner} organization`;
core.setOutput("error", error);
core.setFailed(error);
}
build-docker:
name: "Build"
needs:
- create
permissions:
contents: read
checks: write
uses: ./.github/workflows/docker-build.yml
with:
sha: ${{ github.event.client_payload.pull_request.head.sha || github.event.after }}
branch_name: ${{ github.event.client_payload.pull_request.head.ref || github.ref_name }}
secrets: inherit
notification:
if: always()
needs:
- build-docker
- create
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- name: Add reaction to command comment on success
uses: peter-evans/create-or-update-comment@v3
if: needs.build-docker.result != 'failure'
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> Docker image was pushed with the tag `${{ needs.build-docker.outputs.image_version }}`
>
> [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
reactions: "+1"
- name: Add reaction to command comment on failure
uses: peter-evans/create-or-update-comment@v3
if: needs.build-docker.result == 'failure'
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> **Error**: failed to execute "${{ github.event.client_payload.slash_command.args.unnamed.arg1 }}" command
> [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
reactions: "-1"
help:
if: github.event.client_payload.slash_command.args.unnamed.arg1 == 'help'
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Update comment
uses: peter-evans/create-or-update-comment@v3
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> Command | Description
> --- | ---
> /docker build | Build and push custom docker image
reaction-type: hooray