Skip to content

Commit a42f32b

Browse files
Add a workflow to keep wp-cli/wp-cli up to date (#507)
* Add a workflow to keep `wp-cli/wp-cli` up to date * Run on `push` while we're testing * Revert "Run on `push` while we're testing" This reverts commit 0dc5e79.
1 parent fec367c commit a42f32b

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Update wp-cli framework
2+
3+
on:
4+
workflow_call:
5+
6+
# Cancels all previous workflow runs for the same branch that have not yet completed.
7+
concurrency:
8+
# The concurrency group contains the workflow name and the branch name.
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
13+
jobs:
14+
15+
update-framework: #----------------------------------------------------------
16+
name: Update wp-cli framework
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Check out source code
20+
uses: actions/checkout@v3
21+
22+
- name: Set up PHP envirnoment
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: '7.4'
26+
env:
27+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Check existence of composer.json file
30+
id: check_composer_file
31+
uses: andstor/file-existence-action@v2
32+
with:
33+
files: "composer.json"
34+
35+
- name: Install Composer dependencies & cache dependencies
36+
if: steps.check_composer_file.outputs.files_exists == 'true'
37+
uses: "ramsey/composer-install@v2"
38+
env:
39+
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
40+
with:
41+
# Bust the cache at least once a month - output format: YYYY-MM.
42+
custom-cache-suffix: $(date -u "+%Y-%m")
43+
44+
- name: Configure git user
45+
run: |
46+
git config --global user.email "alain.schlesser@gmail.com"
47+
git config --global user.name "Alain Schlesser"
48+
49+
- name: Check if remote branch exists
50+
run: echo "REMOTE_BRANCH_EXISTS=$([[ -z $(git ls-remote --heads origin update-framework) ]] && echo "0" || echo "1")" >> $GITHUB_ENV
51+
52+
- name: Create branch to base pull request on
53+
if: env.REMOTE_BRANCH_EXISTS == 0
54+
run: |
55+
git checkout -b update-framework
56+
57+
- name: Fetch existing branch to add commits to
58+
if: env.REMOTE_BRANCH_EXISTS == 1
59+
run: |
60+
git fetch --all --prune
61+
git checkout update-framework
62+
git pull --no-rebase
63+
64+
- name: Update wp-cli framework
65+
run: |
66+
composer update wp-cli/wp-cli
67+
68+
- name: Check if there are changes
69+
run: echo "CHANGES_DETECTED=$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1")" >> $GITHUB_ENV
70+
71+
- name: Commit changes
72+
if: env.CHANGES_DETECTED == 1
73+
run: |
74+
git add composer.lock
75+
git commit -m "Update wp-cli framework - $(date +'%Y-%m-%d')"
76+
git push origin update-framework
77+
78+
- name: Create pull request
79+
if: |
80+
env.CHANGES_DETECTED == 1 &&
81+
env.REMOTE_BRANCH_EXISTS == 0
82+
uses: repo-sync/pull-request@v2
83+
with:
84+
source_branch: update-framework
85+
destination_branch: ${{ github.event.repository.default_branch }}
86+
github_token: ${{ secrets.GITHUB_TOKEN }}
87+
pr_title: Update wp-cli framework
88+
pr_body: "**This is an automated pull-request**\n\nUpdates the `wp-cli/wp-cli` framework to the latest changeset."
89+
pr_label: scope:framework

0 commit comments

Comments
 (0)