|
9 | 9 | required: false |
10 | 10 | default: '' |
11 | 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 | +
|
12 | 49 | build-and-deploy: |
13 | 50 | name: Build and deploy |
14 | | - runs-on: [ubuntu-latest] |
| 51 | + runs-on: ubuntu-latest |
| 52 | + needs: verify |
| 53 | + if: ${{ needs.verify.outputs.rebuild == 'true' }} |
15 | 54 | steps: |
16 | 55 | - name: Checkout code |
17 | 56 | uses: actions/checkout@v4 |
|
31 | 70 | restore-keys: ${{ runner.os }}-composer- |
32 | 71 | - name: Install dependencies |
33 | 72 | run: composer install --prefer-dist |
34 | | - - name: Fetch latest release version if not provided |
35 | | - id: get-latest-version |
36 | | - env: |
37 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
38 | | - INPUT_VERSION: ${{ github.event.inputs.version }} |
39 | | - run: | |
40 | | - if [ -z "$INPUT_VERSION" ]; then |
41 | | - VERSION=$(gh release view --repo "$GITHUB_REPOSITORY_OWNER/woocommerce" --json tagName -q .tagName) |
42 | | - else |
43 | | - VERSION="$INPUT_VERSION" |
44 | | - fi |
45 | | -
|
46 | | - echo "version=$VERSION" >> $GITHUB_OUTPUT |
47 | 73 | - name: Build |
48 | 74 | run: | |
49 | | - ./deploy.sh --build-only -s ${{ steps.get-latest-version.outputs.version }} -r "$GITHUB_REPOSITORY_OWNER/woocommerce" |
| 75 | + ./deploy.sh --build-only -s ${{ needs.verify.outputs.version }} -r "$GITHUB_REPOSITORY_OWNER/woocommerce" |
50 | 76 | - name: Deploy to GitHub Pages |
51 | 77 | if: success() |
52 | 78 | uses: crazy-max/ghaction-github-pages@59173cb633d9a3514f5f4552a6a3e62c6710355c # v2 |
|
55 | 81 | with: |
56 | 82 | target_branch: gh-pages |
57 | 83 | build_dir: build/api |
58 | | - commit_message: "${{ format('Build: {0}', steps.get-latest-version.outputs.version) }}" |
| 84 | + commit_message: "${{ format('Build: {0}', needs.verify.outputs.version) }}" |
0 commit comments