Merge pull request #192 from rtCamp/update/artifact-version #193
This file contains 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: Build plugin | |
on: | |
push: | |
# Don't run for irrelevant changes. | |
paths-ignore: | |
- 'docs/**' | |
- '!.github/workflows/**' | |
- '!.github/workflows/build-and-deploy.yml' | |
- '.storybook/**' | |
- '.wordpress-org/**' | |
- '__mocks__/**' | |
- '__static__/**' | |
- 'bin/**' | |
- 'tests/**' | |
branches: | |
- main | |
- release/* | |
pull_request: | |
# Don't run for irrelevant changes. | |
paths-ignore: | |
- 'docs/**' | |
- '!.github/workflows/**' | |
- '!.github/workflows/build-and-deploy.yml' | |
- '.storybook/**' | |
- '.wordpress-org/**' | |
- '__mocks__/**' | |
- '__static__/**' | |
- 'bin/**' | |
- 'tests/**' | |
# Cancels all previous workflow runs for pull requests that have not completed. | |
concurrency: | |
# The concurrency group contains the workflow name and the branch name for pull requests | |
# or the commit hash for any other events. | |
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} | |
cancel-in-progress: true | |
jobs: | |
bundle-size: | |
name: Bundle size check | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 | |
# The action cannot annotate the PR when run from a PR fork or authored by Dependabot. | |
if: > | |
github.event_name == 'pull_request' && | |
github.event.pull_request.draft == false && | |
github.event.pull_request.head.repo.fork == false && | |
github.event.pull_request.user.login != 'dependabot[bot]' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Read .nvmrc | |
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)" | |
id: nvm | |
- name: Setup Node | |
uses: actions/[email protected] | |
with: | |
node-version: ${{ steps.nvm.outputs.NVMRC }} | |
cache: npm | |
- name: Bundle size check | |
uses: preactjs/compressed-size-action@v2 | |
with: | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
pattern: '{assets/js/*.js,assets/css/*.css}' | |
build-script: 'build:js' | |
minimum-change-threshold: 100 | |
# Ignore webpack content hash in bundle filenames. | |
strip-hash: '.*-(\w{20})\.js$' | |
build: | |
name: Package ZIP files | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Read .nvmrc | |
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)" | |
id: nvm | |
- name: Setup Node | |
uses: actions/[email protected] | |
with: | |
node-version: ${{ steps.nvm.outputs.NVMRC }} | |
cache: npm | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '7.4' | |
coverage: none | |
tools: composer | |
- name: Get Composer cache directory | |
id: composer-cache | |
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | |
- name: Setup Composer cache | |
uses: pat-s/[email protected] | |
with: | |
path: ${{ steps.composer-cache.outputs.dir }} | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: | | |
${{ runner.os }}-composer- | |
${{ runner.os }}- | |
- name: Install dependencies | |
run: | | |
npm ci | |
composer install --prefer-dist --no-progress --no-interaction | |
env: | |
CI: true | |
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true | |
- name: Build plugin | |
run: | | |
npm run build:js | |
npm run workflow:version -- --nightly | |
mkdir -p build/web-stories-regular build/web-stories-dev | |
- name: Bundle regular version | |
run: | | |
npm run workflow:build-plugin | |
mv build/web-stories build/web-stories-regular/ | |
- name: Bundle development version | |
run: | | |
rm -rf assets/css/* assets/js/* | |
NODE_ENV=development npx webpack --config webpack.config.cjs | |
npm run workflow:build-plugin | |
mv build/web-stories build/web-stories-dev/ | |
- name: Upload regular bundle | |
uses: actions/upload-artifact@v4 | |
with: | |
name: web-stories | |
path: build/web-stories-regular | |
- name: Upload development bundle | |
uses: actions/upload-artifact@v4 | |
with: | |
name: web-stories-dev | |
path: build/web-stories-dev | |
upload-to-wiki: | |
name: Upload ZIP files to storage | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 | |
# Only run if the PR was not authored by Dependabot and it is not a draft or not from a fork. | |
if: > | |
github.event.pull_request.draft == false && | |
github.event.pull_request.head.repo.fork == false && | |
github.event.pull_request.user.login != 'dependabot[bot]' | |
needs: build | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
repository: ${{ github.repository }}.wiki | |
ref: master | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: ${{ github.ref }} | |
- name: ZIP artifacts | |
run: | | |
rm -rf web-stories.zip web-stories-dev.zip | |
(cd web-stories && zip -mrT web-stories.zip web-stories && mv web-stories.zip ../ ) | |
(cd web-stories-dev && zip -mrT web-stories-dev.zip web-stories && mv web-stories-dev.zip ../ ) | |
working-directory: ${{ github.ref }} | |
- name: Commit updates | |
run: | | |
git add . | |
git status | |
git commit -m "Build and publish ${{ github.ref }}" | |
git pull --no-edit --quiet | |
git push origin master | |
env: | |
GIT_AUTHOR_EMAIL: ${{ github.actor }}@users.noreply.github.com | |
GIT_AUTHOR_NAME: ${{ github.actor }} | |
GIT_COMMITTER_EMAIL: ${{ github.actor }}@users.noreply.github.com | |
GIT_COMMITTER_NAME: ${{ github.actor }} | |
deploy-to-staging: | |
name: Deploy to staging environment | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 | |
needs: [build] | |
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Download full bundle | |
uses: actions/download-artifact@v4 | |
with: | |
name: web-stories | |
path: build | |
- name: Setup SSH Keys and known_hosts | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.PANTHEON_DEPLOY_KEY }} | |
- name: Run deployment | |
run: bash bin/deploy-to-test-environment.sh |