From 2c03d6cc825d920c835ea0b955ce8c937549bb0c Mon Sep 17 00:00:00 2001 From: Paul Sealock Date: Tue, 6 Dec 2022 06:28:02 +1300 Subject: [PATCH] Live Branches: Avoid running job on community PRs (#35795) --- .github/workflows/pr-build-live-branch.yml | 153 +++++++++++---------- 1 file changed, 77 insertions(+), 76 deletions(-) diff --git a/.github/workflows/pr-build-live-branch.yml b/.github/workflows/pr-build-live-branch.yml index fa003da04c3..00706c67d74 100644 --- a/.github/workflows/pr-build-live-branch.yml +++ b/.github/workflows/pr-build-live-branch.yml @@ -1,83 +1,84 @@ name: Build Live Branch on: - pull_request: + pull_request: concurrency: - # Cancel concurrent jobs on pull_request but not push, by including the run_id in the concurrency group for the latter. - group: build-${{ github.event_name == 'push' && github.run_id || 'pr' }}-${{ github.ref }} - cancel-in-progress: true + # Cancel concurrent jobs on pull_request but not push, by including the run_id in the concurrency group for the latter. + group: build-${{ github.event_name == 'push' && github.run_id || 'pr' }}-${{ github.ref }} + cancel-in-progress: true jobs: - build: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v3 - - - name: Get current version - id: version - uses: actions/github-script@v6.3.3 - with: - script: - const { getVersion } = require( './.github/workflows/scripts/get-plugin-version' ); - const version = await getVersion( 'woocommerce' ); - core.setOutput( 'version', version ); - - - name: Setup WooCommerce Monorepo - uses: ./.github/actions/setup-woocommerce-monorepo - with: - build: false + build: + if: github.repository_owner == 'woocommerce' + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 - - name: Prepare plugin zips - id: prepare - env: - CURRENT_VERSION: ${{ steps.version.outputs.version }} - run: | - - # Current version must compare greather than any previously used current version for this PR. - # Assume GH run IDs are monotonic. - VERSUFFIX="${GITHUB_RUN_ID}-g$(git rev-parse --short HEAD)" - - CURRENT_VERSION="$CURRENT_VERSION-$VERSUFFIX" - - sed -i -e 's/Version: .*$/Version: '"$CURRENT_VERSION"'/' "$GITHUB_WORKSPACE/plugins/woocommerce/woocommerce.php" - echo "$CURRENT_VERSION" > "$GITHUB_WORKSPACE/plugins/woocommerce/version.txt" - - cd "$GITHUB_WORKSPACE/plugins/woocommerce" - bash bin/build-zip.sh - - mkdir "$GITHUB_WORKSPACE/zips" - cp "$GITHUB_WORKSPACE/plugins/woocommerce/woocommerce.zip" "$GITHUB_WORKSPACE/zips/woocommerce.zip" - cd "$GITHUB_WORKSPACE/zips" - unzip woocommerce.zip - rm woocommerce.zip - mv woocommerce woocommerce-dev - zip -q -r "woocommerce-dev.zip" "woocommerce-dev/" - rm -fR "$GITHUB_WORKSPACE/zips/woocommerce-dev" - - # Plugin data is passed as a JSON object. - PLUGIN_DATA="{}" - PLUGIN_DATA=$( jq -c --arg slug "woocommerce" --arg ver "$CURRENT_VERSION" '.[ $slug ] = { version: $ver }' <<<"$PLUGIN_DATA" ) - echo "plugin-data=$PLUGIN_DATA" >> $GITHUB_OUTPUT - - - name: Create plugins artifact - uses: actions/upload-artifact@v3 - if: steps.prepare.outputs.plugin-data != '{}' - with: - name: plugins - path: zips - # Only need to retain for a day since the beta builder slurps it up to distribute. - retention-days: 1 - - - name: Inform Beta Download webhook - if: steps.prepare.outputs.plugin-data != '{}' - env: - SECRET: ${{ secrets.WOOBETA_SECRET }} - PLUGIN_DATA: ${{ steps.prepare.outputs.plugin-data }} - PR: ${{ github.event.number }} - run: | - curl -v --fail -L \ - --url "https://betadownload.jetpack.me/gh-action.php?run_id=$GITHUB_RUN_ID&pr=$PR&commit=$GITHUB_SHA" \ - --form-string "repo=$GITHUB_REPOSITORY" \ - --form-string "branch=${GITHUB_REF#refs/heads/}" \ - --form-string "plugins=$PLUGIN_DATA" \ - --form-string "secret=$SECRET" + - name: Get current version + id: version + uses: actions/github-script@v6.3.3 + with: + script: + const { getVersion } = require( './.github/workflows/scripts/get-plugin-version' ); + const version = await getVersion( 'woocommerce' ); + core.setOutput( 'version', version ); + + - name: Setup WooCommerce Monorepo + uses: ./.github/actions/setup-woocommerce-monorepo + with: + build: false + + - name: Prepare plugin zips + id: prepare + env: + CURRENT_VERSION: ${{ steps.version.outputs.version }} + run: | + + # Current version must compare greather than any previously used current version for this PR. + # Assume GH run IDs are monotonic. + VERSUFFIX="${GITHUB_RUN_ID}-g$(git rev-parse --short HEAD)" + + CURRENT_VERSION="$CURRENT_VERSION-$VERSUFFIX" + + sed -i -e 's/Version: .*$/Version: '"$CURRENT_VERSION"'/' "$GITHUB_WORKSPACE/plugins/woocommerce/woocommerce.php" + echo "$CURRENT_VERSION" > "$GITHUB_WORKSPACE/plugins/woocommerce/version.txt" + + cd "$GITHUB_WORKSPACE/plugins/woocommerce" + bash bin/build-zip.sh + + mkdir "$GITHUB_WORKSPACE/zips" + cp "$GITHUB_WORKSPACE/plugins/woocommerce/woocommerce.zip" "$GITHUB_WORKSPACE/zips/woocommerce.zip" + cd "$GITHUB_WORKSPACE/zips" + unzip woocommerce.zip + rm woocommerce.zip + mv woocommerce woocommerce-dev + zip -q -r "woocommerce-dev.zip" "woocommerce-dev/" + rm -fR "$GITHUB_WORKSPACE/zips/woocommerce-dev" + + # Plugin data is passed as a JSON object. + PLUGIN_DATA="{}" + PLUGIN_DATA=$( jq -c --arg slug "woocommerce" --arg ver "$CURRENT_VERSION" '.[ $slug ] = { version: $ver }' <<<"$PLUGIN_DATA" ) + echo "plugin-data=$PLUGIN_DATA" >> $GITHUB_OUTPUT + + - name: Create plugins artifact + uses: actions/upload-artifact@v3 + if: steps.prepare.outputs.plugin-data != '{}' + with: + name: plugins + path: zips + # Only need to retain for a day since the beta builder slurps it up to distribute. + retention-days: 1 + + - name: Inform Beta Download webhook + if: steps.prepare.outputs.plugin-data != '{}' + env: + SECRET: ${{ secrets.WOOBETA_SECRET }} + PLUGIN_DATA: ${{ steps.prepare.outputs.plugin-data }} + PR: ${{ github.event.number }} + run: | + curl -v --fail -L \ + --url "https://betadownload.jetpack.me/gh-action.php?run_id=$GITHUB_RUN_ID&pr=$PR&commit=$GITHUB_SHA" \ + --form-string "repo=$GITHUB_REPOSITORY" \ + --form-string "branch=${GITHUB_REF#refs/heads/}" \ + --form-string "plugins=$PLUGIN_DATA" \ + --form-string "secret=$SECRET"