-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
105 lines (96 loc) · 4.14 KB
/
action.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
102
103
104
105
name: Scaffold and Commit Action
description: |
This action determines the type of repository based on its properties,
copies the files from the corresponding scaffolding directory,
overlays them onto the workspace, and commits the changes to a Pull Request.
A GitHub App is required because scaffolding may need to commit to protected branches and
any updates of `.github/workflows` needs the `workflows:write` permission, only available via
a GitHub App. Additionally, if any of the commits should trigger GitHub Actions, the default
`GITHUB_TOKEN` will not work.
inputs:
github_app_id:
description: 'GitHub App ID'
required: true
github_app_private_key:
description: 'GitHub App Private Key'
required: true
runs:
using: 'composite'
steps:
- uses: actions/create-github-app-token@v1
id: github-app
with:
app-id: ${{ input.github_app_id }}
private-key: ${{ input.github_app_private_key }}
- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ steps.github-app.outputs.token }}
- name: Get Repository Metadata
id: repo
shell: bash
env:
GH_TOKEN: ${{ steps.github-app.outputs.token }}
run: |
response=$(gh api /repos/${{ github.repository }}/properties/values)
properties=$(echo "$response" | jq -cr 'reduce .[] as $item ({}; .[$item.property_name] = $item.value)')
type=$(echo "$properties" | jq -r .type)
echo "properties=$properties" >> $GITHUB_OUTPUT
echo "type=$type" >> $GITHUB_OUTPUT
echo "branch=${{ github.event.pull_request.head.ref || github.ref_name }}" >> $GITHUB_OUTPUT
echo "**Ref Name:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "**Default Branch:** ${{github.event.repository.default_branch }}" >> $GITHUB_STEP_SUMMARY
echo "**Head Ref:** ${{ github.event.pull_request.head.ref }}" >> $GITHUB_STEP_SUMMARY
echo "**Repo Type**: $type" >> $GITHUB_STEP_SUMMARY
- name: Run Scaffolding
id: scaffolding
shell: bash
run: |
type="${{ steps.repo.outputs.type }}"
scaffolding_path="${{github.action_path}}/scaffolding/$type"
if [ -f "${scaffolding_path}/Makefile" ]; then
echo "Running scaffolding for '$type'..."
echo "## Scaffolding" >> $GITHUB_STEP_SUMMARY
echo '```shell' >> $GITHUB_STEP_SUMMARY
cd $scaffolding_path && (make all >> $GITHUB_STEP_SUMMARY 2>&1)
echo '```' >> $GITHUB_STEP_SUMMARY
else
echo "Scaffolding for type '$type' not supported."
echo '> [!WARNING]' >> $GITHUB_STEP_SUMMARY
echo '> ## Unsupported Repository Type' >> $GITHUB_STEP_SUMMARY
echo "> Scaffold for type `'$type'` not found." >> $GITHUB_STEP_SUMMARY
exit 1
fi
# Open New PR for scheduled jobs running in the default branch
- name: Commit and Push Changes to a New Pull Request
uses: peter-evans/create-pull-request@v6
if: ${{ steps.repo.outputs.branch == github.event.repository.default_branch }}
id: auto-pr
with:
token: ${{ steps.github-app.outputs.token }}
commit-message: 'chore: update repo scaffolding'
branch: 'auto-update/scaffolding'
base: ${{ steps.repo.outputs.branch }}
title: 'Update Repository Scaffolding'
labels: |
auto-update
scaffolding
no-release
body: |
## what
- This pull request includes the scaffolding files overlaid onto the repository.
## why
- Update the repository whenever the scaffolding files change from the organization's `.github` repository.
# Update existing PR for jobs running in a PR (e.g. non-default branch)
# Protected branches will need a GitHub App to update the PR
- uses: stefanzweifel/git-auto-commit-action@v5
if: ${{ steps.repo.outputs.branch != github.event.repository.default_branch }}
name: Commit changes to current Pull Request
id: auto-commit
env:
GITHUB_TOKEN: ${{ steps.github-app.outputs.token }}
with:
commit_message: "chore: update repo scaffolding"
commit_user_name: org-action 🏗️
commit_user_email: [email protected]
commit_author: org-action 🏗️ <[email protected]>