-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (120 loc) · 5.35 KB
/
Copy pathupdate_as.yml
File metadata and controls
134 lines (120 loc) · 5.35 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: 'Update Action Scheduler'
on:
pull_request:
jobs:
update_as:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Checkout slic
uses: actions/checkout@v4
with:
repository: stellarwp/slic
ref: main
path: slic
fetch-depth: 1
- name: Get Composer Cache Directory
id: get-composer-cache-dir
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v4
id: composer-cache
with:
path: ${{ steps.get-composer-cache-dir.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
# ------------------------------------------------------------------------------
# Initialize slic
# ------------------------------------------------------------------------------
- name: Move slic directory up
run: |
mv slic ./../slic
- name: Set up slic env vars
run: |
echo "SLIC_COMPOSER_VERSION=2" >> $GITHUB_ENV
echo "SLIC_BIN=${GITHUB_WORKSPACE}/../slic/slic" >> $GITHUB_ENV
echo "SLIC_WP_DIR=${GITHUB_WORKSPACE}/../slic/_wordpress" >> $GITHUB_ENV
- name: Set run context for slic
run: echo "SLIC=1" >> $GITHUB_ENV && echo "CI=1" >> $GITHUB_ENV
- name: Start ssh-agent
run: |
mkdir -p "${HOME}/.ssh";
ssh-agent -a /tmp/ssh_agent.sock;
- name: Export SSH_AUTH_SOCK env var
run: echo "SSH_AUTH_SOCK=/tmp/ssh_agent.sock" >> $GITHUB_ENV
- name: Set up slic for CI
run: |
cd ${GITHUB_WORKSPACE}/..
${SLIC_BIN} here
${SLIC_BIN} interactive off
${SLIC_BIN} build-prompt off
${SLIC_BIN} build-subdir off
${SLIC_BIN} xdebug off
${SLIC_BIN} composer-cache set /home/runner/.cache/composer
${SLIC_BIN} debug on
${SLIC_BIN} info
${SLIC_BIN} config
- name: Init the WordPress container
run: |
${SLIC_BIN} up wordpress
${SLIC_BIN} wp core version
${SLIC_BIN} wp core update --force --version=6.7
${SLIC_BIN} wp core version
${SLIC_BIN} use shepherd
- name: Install WooCommerce
run: ${SLIC_BIN} site-cli plugin install woocommerce
- name: Get Shepherd's AS Version from composer.json
run: |
cd ${GITHUB_WORKSPACE}/
SHEPHERD_AS_VERSION=$(grep -E '"woocommerce/action-scheduler": "[0-9]+\.[0-9]+\.[0-9]+"' composer.json | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
echo "Shepherd's AS Version: $SHEPHERD_AS_VERSION"
echo "SHEPHERD_AS_VERSION=$SHEPHERD_AS_VERSION" >> $GITHUB_ENV
- name: Get WooCommerce's AS Version php eval
run: |
cd ${GITHUB_WORKSPACE}/
echo "<?php do_action( 'plugins_loaded' ); echo ActionScheduler_Versions::instance()->latest_version();" > as_version.php
${SLIC_BIN} site-cli plugin activate woocommerce
${SLIC_BIN} site-cli eval-file as_version.php > as_version.txt
WC_AS_VERSION=$(grep -E '^[0-9]+\.[0-9]+\.[0-9]+' as_version.txt)
rm as_version.php as_version.txt
echo "WooCommerce's AS Version: $WC_AS_VERSION"
echo "WC_AS_VERSION=$WC_AS_VERSION" >> $GITHUB_ENV
- name: Compare Shepherd's and WooCommerce's AS Versions
run: |
if [ "$SHEPHERD_AS_VERSION" != "$WC_AS_VERSION" ]; then
echo "Shepherd's AS Version: $SHEPHERD_AS_VERSION"
echo "WooCommerce's AS Version: $WC_AS_VERSION"
exit 1
fi
- name: create new branch with updated AS version
if: ${{ failure() }}
run: |
cd ${GITHUB_WORKSPACE}/
HEAD_BRANCH="task/update-as-for/${{ github.head_ref }}"
git config --global user.email "actions@github.com"
git config --global user.name "github-actions"
git checkout -b "$HEAD_BRANCH"
echo "Created branch $HEAD_BRANCH"
echo "Updating Action Scheduler to $WC_AS_VERSION"
${SLIC_BIN} composer require woocommerce/action-scheduler:$WC_AS_VERSION
git add composer.json composer.lock
git commit -m "Update Action Scheduler to $WC_AS_VERSION"
git push origin "$HEAD_BRANCH"
- name: Create Pull Request using GitHub CLI
if: ${{ failure() }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Creating PR using GitHub CLI..."
HEAD_BRANCH="task/update-as-for/${{ github.head_ref }}"
PR_BODY=$(printf "This is an automated PR created by ${{ github.actor }} for [PR](${{ github.event.pull_request.html_url }}). It was generated by [this GitHub Action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})")
PR_URL=$(gh pr create \
--base "${{ github.head_ref }}" \
--head "$HEAD_BRANCH" \
--title "[BOT] Update AS Version to match WC" \
--label "automation" \
--assignee "${{ github.actor }}" \
--body-file - <<< "$PR_BODY" )
gh pr comment ${{ github.event.pull_request.number }} --body "PR to update Action Scheduler version to match WooCommerce version has been created: $PR_URL"