-
Notifications
You must be signed in to change notification settings - Fork 6
88 lines (74 loc) · 3.43 KB
/
reusable-regenerate-readme.yml
File metadata and controls
88 lines (74 loc) · 3.43 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Regenerate README file
on:
workflow_call:
permissions:
contents: write
pull-requests: write
# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
regenerate-readme:
name: Regenerate README.md file
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'wp-cli' && ! contains(fromJson('[".github", "wp-cli", "wp-cli-bundle", "wp-super-cache-cli", "php-cli-tools", "wp-config-transformer", "wp-cli.github.com"]'), github.event.repository.name) }}
steps:
- name: Check out source code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Set up PHP environment
uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # v2
with:
php-version: 'latest'
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check existence of composer.json file
id: check_composer_file
run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT"
- name: Install Composer dependencies & cache dependencies
if: steps.check_composer_file.outputs.files_exists == 'true'
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # 4.0.0
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
- name: Install WP-CLI
run: |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar
sudo mv wp-cli-nightly.phar /usr/local/bin/wp
sudo chmod +x /usr/local/bin/wp
- name: Regenerate README.md file
run: |
wp package install "wp-cli/scaffold-package-command:^2"
wp scaffold package-readme --branch=${GITHUB_EVENT_REPOSITORY_DEFAULT_BRANCH} --force .
env:
GITHUB_EVENT_REPOSITORY_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
- name: Commit and Create Pull Request
env:
GH_TOKEN: ${{ github.token }}
PR_BODY: |
**This is an automated pull-request**
Refreshes the `README.md` file with the latest changes to the docblocks in the source code.
run: |
if [ -n "$(git status --porcelain)" ]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b regenerate-readme
git add README.md
git commit -m "Regenerate README file"
git push -f origin regenerate-readme
PR_NUMBER=$(gh pr list --head regenerate-readme --json number --jq '.[0].number // empty')
if [ -z "$PR_NUMBER" ]; then
gh pr create \
--title "Regenerate README file" \
--body "$PR_BODY" \
--label "scope:documentation" \
--base "${{ github.event.repository.default_branch }}" \
--head "regenerate-readme"
else
gh pr edit "$PR_NUMBER" \
--title "Regenerate README file" \
--body "$PR_BODY" \
--add-label "scope:documentation" \
--base "${{ github.event.repository.default_branch }}"
fi
fi