Skip to content

Commit ad2a1db

Browse files
authored
Merge pull request #28 from woocommerce/deploy-job-fixes
Various deploy job fixes
2 parents 3fa2077 + 5407b9b commit ad2a1db

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

.github/workflows/deploy.yml

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,69 @@
11
name: GitHub Pages deploy
22
on:
3+
schedule:
4+
- cron: '0 23 * * *'
35
workflow_dispatch:
46
inputs:
57
version:
6-
description: 'WooCommerce Version'
7-
required: true
8+
description: 'WooCommerce version (defaults to latest release in repository)'
9+
required: false
10+
default: ''
811
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+
949
build-and-deploy:
1050
name: Build and deploy
11-
runs-on: [ubuntu-latest]
51+
runs-on: ubuntu-latest
52+
needs: verify
53+
if: ${{ needs.verify.outputs.rebuild == 'true' }}
1254
steps:
1355
- name: Checkout code
14-
uses: actions/checkout@v2
56+
uses: actions/checkout@v4
1557
- name: Setup PHP with composer v2
1658
uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1
1759
with:
18-
php-version: '7.4'
60+
php-version: '8.1'
1961
tools: composer:v2
2062
- name: Get composer cache directory
2163
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
2365
- name: Cache dependencies
24-
uses: actions/cache@v2
66+
uses: actions/cache@v4
2567
with:
2668
path: ${{ steps.composer-cache.outputs.dir }}
2769
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
@@ -30,7 +72,7 @@ jobs:
3072
run: composer install --prefer-dist
3173
- name: Build
3274
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"
3476
- name: Deploy to GitHub Pages
3577
if: success()
3678
uses: crazy-max/ghaction-github-pages@59173cb633d9a3514f5f4552a6a3e62c6710355c # v2
@@ -39,3 +81,4 @@ jobs:
3981
with:
4082
target_branch: gh-pages
4183
build_dir: build/api
84+
commit_message: "${{ format('Build: {0}', needs.verify.outputs.version) }}"

0 commit comments

Comments
 (0)