Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making reusable-regenerate-readme GitHub-y #53

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions .github/workflows/reusable-regenerate-readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true


jobs:

regenerate-readme: #----------------------------------------------------------
Copy link
Author

@szepeviktor szepeviktor Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may get emotional.
πŸ‘¨πŸ»β€πŸŽ¨

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) }}
Expand All @@ -21,51 +20,55 @@ jobs:
uses: actions/checkout@v3

- name: Set up PHP envirnoment
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
Comment on lines -24 to +27
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put things in chronological order.
env is prerequisite.


- name: Check existence of composer.json file
id: check_composer_file
uses: andstor/file-existence-action@v2
with:
files: "composer.json"
files: composer.json

- name: Install Composer dependencies & cache dependencies
if: steps.check_composer_file.outputs.files_exists == 'true'
uses: "ramsey/composer-install@v2"
if: ${{ steps.check_composer_file.outputs.files_exists == 'true' }}
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
uses: ramsey/composer-install@v2
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
custom-cache-suffix: |
$(date --utc "+%Y-%m")
Copy link
Author

@szepeviktor szepeviktor Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Protect shell scripts. Use long options.


- name: Configure git user
run: |
git config --global user.email "[email protected]"
git config --global user.name "Alain Schlesser"

- name: Check if remote branch exists
run: echo "REMOTE_BRANCH_EXISTS=$([[ -z $(git ls-remote --heads origin regenerate-readme) ]] && echo "0" || echo "1")" >> $GITHUB_ENV

id: check_remote_branch
run: >
echo "exists=$(git ls-remote --exit-code --heads origin regenerate-readme &>/dev/null
&& echo "true" || echo "false")" >>"${GITHUB_OUTPUT}"

- name: Create branch to base pull request on
if: env.REMOTE_BRANCH_EXISTS == 0
if: ${{ steps.check_remote_branch.outputs.exists == 'false' }}
run: |
git checkout -b regenerate-readme

- name: Fetch existing branch to add commits to
if: env.REMOTE_BRANCH_EXISTS == 1
if: ${{ steps.check_remote_branch.outputs.exists == 'true' }}
run: |
git fetch --all --prune
git checkout regenerate-readme
git pull --no-rebase

- name: Install WP-CLI
- name: Install WP-CLI nightly
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 mv --verbose wp-cli-nightly.phar /usr/local/bin/wp
sudo chmod +x /usr/local/bin/wp

- name: Regenerate README.md file
Expand All @@ -74,25 +77,31 @@ jobs:
wp scaffold package-readme --branch=${{ github.event.repository.default_branch }} --force .

- name: Check if there are changes
run: echo "CHANGES_DETECTED=$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1")" >> $GITHUB_ENV
id: check_changes
run: >
echo "detected=$(test -n "$(git status --porcelain 2>/dev/null)"
&& echo "true" || echo "false")" >>"${GITHUB_OUTPUT}"

- name: Commit changes
if: env.CHANGES_DETECTED == 1
if: ${{ steps.check_changes.outputs.detected == 'true' }}
run: |
git add README.md
git commit -m "Regenerate README file - $(date +'%Y-%m-%d')"
git push origin regenerate-readme

- name: Create pull request
if: |
env.CHANGES_DETECTED == 1 &&
env.REMOTE_BRANCH_EXISTS == 0
if: >
${{ steps.check_changes.outputs.detected == 'true'
&& steps.check_remote_branch.outputs.exists == 'false' }}
uses: repo-sync/pull-request@v2
with:
source_branch: regenerate-readme
destination_branch: ${{ github.event.repository.default_branch }}
github_token: ${{ secrets.GITHUB_TOKEN }}
pr_title: Regenerate README file
pr_body: "**This is an automated pull-request**\n\nRefreshes the `README.md` file with the latest changes to the docblocks in the source code."
pr_body: |
**This is an automated pull-request**

Refreshes the `README.md` file with the latest changes to the docblocks in the source code.
pr_reviewer: schlessera
pr_label: scope:documentation