Repository navigation
71 lines (66 loc) · 2.77 KB
/
Copy pathRegister.yml
File metadata and controls
71 lines (66 loc) · 2.77 KB
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
# MANAGED by EpiAwarePackageTools.scaffold — do not edit by hand.
#
# Triggers Julia General Registry registration by posting the
# `@JuliaRegistrator register` comment on `main`'s HEAD commit — the same
# comment a maintainer would type by hand, so no extra service or token
# beyond `GITHUB_TOKEN` is needed. Two ways to fire it, both gated on the
# actor having write access:
#
# - Comment `/register` on any issue or pull request.
# - Run this workflow manually (Actions -> Register -> Run workflow).
#
# JuliaRegistrator (the org's GitHub App) then reacts to the commit comment,
# opens the registry PR, and TagBot creates the release once it merges.
name: Register
on:
issue_comment:
types: [created]
workflow_dispatch:
jobs:
register:
if: >-
github.event_name == 'workflow_dispatch' ||
startsWith(github.event.comment.body, '/register')
runs-on: ubuntu-latest
# `contents: write` — posting the commit comment needs Contents write.
# `issues: write` — posting the permission-denied reaction needs Issues
# write (a PR conversation comment is an issue comment for this
# endpoint). The permission check itself needs no extra scope: Metadata
# read is always available to `GITHUB_TOKEN`.
permissions:
contents: write
issues: write
steps:
- name: Check permissions
id: check-permissions
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
ACTOR="${{ github.actor }}"
else
ACTOR="${{ github.event.comment.user.login }}"
fi
PERMISSION=$(gh api "repos/${{ github.repository }}/collaborators/$ACTOR/permission" --jq '.permission')
echo "$ACTOR has permission: $PERMISSION"
if [[ "$PERMISSION" == "admin" || "$PERMISSION" == "write" || "$PERMISSION" == "maintain" ]]; then
echo "has_permission=true" >> "$GITHUB_OUTPUT"
else
echo "has_permission=false" >> "$GITHUB_OUTPUT"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Trigger JuliaRegistrator
if: steps.check-permissions.outputs.has_permission == 'true'
run: |
gh api "repos/${{ github.repository }}/commits/main/comments" \
--method POST --field body='@JuliaRegistrator register'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: React with permission denied
if: >-
github.event_name == 'issue_comment' &&
steps.check-permissions.outputs.has_permission == 'false'
run: |
gh api "repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions" \
--method POST --field content='-1'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}