godaddy-wordpress/go

View on GitHub
.github/workflows/create-artifact.yml

Summary

Maintainability
Test Coverage
# Handles the build process for the theme, which includes creating and storing
# an artifact in the workflow.

name: Create Artifact

on:
  workflow_call:
    inputs:
      retention-days:
        required: false
        type: number
        default: 1

env:
  ARTIFACT_NAME: 'go-theme'
  ARTIFACT_PATH: 'go'
  ARTIFACT_ZIP: 'go.zip'

# First build our theme, then create and store the artifact.
jobs:
  build:
    name: Create Artifact
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          ref: ${{ github.event.repository.default_branch }}

      - name: Setup Node
        uses: actions/setup-node@v3
        with:
          node-version-file: '.nvmrc'
          cache: 'yarn'

      - name: Setup WP-CLI
        uses: godaddy-wordpress/setup-wp-cli@main

      # Yarn is still required on this project, so we need to make sure it is
      # installed globally.
      - name: Install yarn
        run: npm i -g yarn

      - name: Install dependencies
        run: |
          composer install --prefer-dist --optimize-autoloader
          yarn install --immutable

      - name: Build theme
        run: |
          yarn build

      - name: Create distribution artifact
        run: |
          rsync --archive --recursive --filter='protect .git' --delete --prune-empty-dirs --include-from="$GITHUB_WORKSPACE/.distinclude" "$GITHUB_WORKSPACE/" "$GITHUB_WORKSPACE/$ARTIFACT_PATH/"
          zip -r $ARTIFACT_ZIP $ARTIFACT_PATH

      - name: Upload artifact
        uses: actions/upload-artifact@v3
        with:
          name: ${{ env.ARTIFACT_NAME }}
          path: ${{ env.ARTIFACT_ZIP }}
          if-no-files-found: error
          retention-days: ${{ inputs.retention-days }}