|
1 | 1 | name: GitHub Pages deploy
|
2 | 2 | on:
|
| 3 | + schedule: |
| 4 | + - cron: '0 23 * * *' |
3 | 5 | workflow_dispatch:
|
4 | 6 | inputs:
|
5 | 7 | version:
|
6 |
| - description: 'WooCommerce Version' |
7 |
| - required: true |
| 8 | + description: 'WooCommerce version (defaults to latest release in repository)' |
| 9 | + required: false |
| 10 | + default: '' |
8 | 11 | jobs:
|
| 12 | + verify: |
| 13 | + name: Verify if a rebuild is needed |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + version: ${{ steps.get-latest-version.outputs.version }} |
| 17 | + rebuild: ${{ steps.check-if-built.outputs.rebuild }} |
| 18 | + steps: |
| 19 | + - name: Checkout repo |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + - name: Fetch latest release version if not provided |
| 24 | + id: get-latest-version |
| 25 | + env: |
| 26 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + INPUT_VERSION: ${{ github.event.inputs.version }} |
| 28 | + run: | |
| 29 | + if [ -z "$INPUT_VERSION" ]; then |
| 30 | + VERSION=$(gh release view --repo "$GITHUB_REPOSITORY_OWNER/woocommerce" --json tagName -q .tagName) |
| 31 | + else |
| 32 | + VERSION="$INPUT_VERSION" |
| 33 | + fi |
| 34 | +
|
| 35 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 36 | + - name: Check if build is necessary |
| 37 | + id: check-if-built |
| 38 | + env: |
| 39 | + VERSION: ${{ steps.get-latest-version.outputs.version }} |
| 40 | + run: | |
| 41 | + last_built_version=$(git log -1 --pretty=%B 'origin/gh-pages' | grep -oP '\d+\.\d+\.\d+') |
| 42 | +
|
| 43 | + if [ "$last_built_version" = "$VERSION" ]; then |
| 44 | + echo "rebuild=false" >> $GITHUB_OUTPUT |
| 45 | + else |
| 46 | + echo "rebuild=true" >> $GITHUB_OUTPUT |
| 47 | + fi |
| 48 | +
|
9 | 49 | build-and-deploy:
|
10 | 50 | name: Build and deploy
|
11 |
| - runs-on: [ubuntu-latest] |
| 51 | + runs-on: ubuntu-latest |
| 52 | + needs: verify |
| 53 | + if: ${{ needs.verify.outputs.rebuild == 'true' }} |
12 | 54 | steps:
|
13 | 55 | - name: Checkout code
|
14 |
| - uses: actions/checkout@v2 |
| 56 | + uses: actions/checkout@v4 |
15 | 57 | - name: Setup PHP with composer v2
|
16 | 58 | uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1
|
17 | 59 | with:
|
18 |
| - php-version: '7.4' |
| 60 | + php-version: '8.1' |
19 | 61 | tools: composer:v2
|
20 | 62 | - name: Get composer cache directory
|
21 | 63 | id: composer-cache
|
22 |
| - run: echo "::set-output name=dir::$(composer config cache-files-dir)" |
| 64 | + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT |
23 | 65 | - name: Cache dependencies
|
24 |
| - uses: actions/cache@v2 |
| 66 | + uses: actions/cache@v4 |
25 | 67 | with:
|
26 | 68 | path: ${{ steps.composer-cache.outputs.dir }}
|
27 | 69 | key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
|
30 | 72 | run: composer install --prefer-dist
|
31 | 73 | - name: Build
|
32 | 74 | run: |
|
33 |
| - ./deploy.sh --build-only -s ${{ github.event.inputs.version }} |
| 75 | + ./deploy.sh --build-only -s ${{ needs.verify.outputs.version }} -r "$GITHUB_REPOSITORY_OWNER/woocommerce" |
34 | 76 | - name: Deploy to GitHub Pages
|
35 | 77 | if: success()
|
36 | 78 | uses: crazy-max/ghaction-github-pages@59173cb633d9a3514f5f4552a6a3e62c6710355c # v2
|
|
39 | 81 | with:
|
40 | 82 | target_branch: gh-pages
|
41 | 83 | build_dir: build/api
|
| 84 | + commit_message: "${{ format('Build: {0}', needs.verify.outputs.version) }}" |
0 commit comments