-
Notifications
You must be signed in to change notification settings - Fork 3
79 lines (66 loc) · 2.2 KB
/
repo-ansible.yaml
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
name: Auto-run repo-ansible
on:
workflow_dispatch:
pull_request_target:
paths:
- 'repo.yaml'
push:
branches:
- main
- master
paths:
- 'repo.yaml'
permissions:
contents: write # allow git commits & push
pull-requests: write # allow comments on PR
env:
# XXX alternative to missing ternary syntax
IS_PULL_REQUEST: ${{ github.event_name == 'pull_request_target' && '1' || '0' }}
jobs:
run:
runs-on: ubuntu-latest
steps:
- if: ${{ env.IS_PULL_REQUEST == '0' }}
uses: actions/checkout@v4
- if: ${{ env.IS_PULL_REQUEST == '1' }}
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
- name: repo-ansible
run: |
docker pull ghcr.io/linkorb/repo-ansible:latest >/dev/null
docker run --rm -v "$PWD":/app ghcr.io/linkorb/repo-ansible:latest | tee /tmp/repo_ansible_output
export OUTPUT=$(cat /tmp/repo_ansible_output)
{
echo 'REPO_ANSIBLE_OUTPUT<<EOF'
echo "$OUTPUT"
echo EOF
} >> "$GITHUB_ENV"
if ! echo "$OUTPUT" | grep "changed=0"; then
echo "REPOSITORY_CHANGED=1" >> "$GITHUB_ENV"
fi
- if: ${{ env.IS_PULL_REQUEST == '0' }}
name: commit changes
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
if git commit -m "chore: automatic repo-ansible run #0000"; then
git push
fi
- if: ${{ env.IS_PULL_REQUEST == '1' && env.REPOSITORY_CHANGED == '1' }}
name: comment with changes
uses: actions/github-script@v7
with:
script: |
const changes = process.env.REPO_ANSIBLE_OUTPUT
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Following repo-ansible changes will be applied when merged to main/master branch
\`\`\`shell
${changes}
\`\`\`
`
})