Feat/introduce a run method #190
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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=latest | |
| ${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" |