From 23abf269268befd40b36cde794a2d37a32adf99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9l=C3=A9my=20Ledoux?= Date: Fri, 1 Dec 2023 20:55:30 +0100 Subject: [PATCH] make cleaner workflow (#352) * make cleaner workflow * try and fix it all * remove prod workflow * add missing dependencies * try e2e install * make it release ready * only run release on main push --- .github/workflows/build.yml | 45 +++++++++++++++++ .github/workflows/e2e-tests.yml | 25 +++++----- .github/workflows/release.yml | 40 +++++++++------ .github/workflows/template-test.yml | 28 +++++------ .github/workflows/test.yml | 23 ++++----- .github/workflows/workflow.yml | 76 +++++++++++++++++++++++++++++ 6 files changed, 182 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/workflow.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..bb0200e14 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,45 @@ +name: Build + +on: + workflow_call: + inputs: + nonce: + type: string + required: true + +jobs: + cypress-run: + runs-on: ubuntu-latest + steps: + - name: Checkout branch + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: 18.x + + - name: Remove Postinstall Script + run: npm pkg set scripts.postinstall="echo no-postinstall" + + - name: Install Dependencies + run: yarn install --frozen-lockfile + env: + CI: true + + - name: Generate icon files + run: | + yarn turbo run build --filter=@cypress-design/css + yarn workspace @cypress-design/icon-registry svg-to-ts-constants + yarn workspace @cypress-design/icon-registry node ./build-icons.mjs + + - name: Build Components + run: yarn run build:components + + - name: Cache node_modules and built dist files + uses: actions/cache@v3 + with: + key: ${{ inputs.nonce }} + path: | + ./components + ./node_modules diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 7446108ca..3894524c8 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -1,15 +1,16 @@ name: Build each test -on: [push] +on: + workflow_call: + inputs: + nonce: + type: string + required: true jobs: build-projects: runs-on: ubuntu-latest steps: - - name: Get Yarn cache path - id: yarn-cache - run: echo "::set-output name=dir::$(yarn cache dir)" - - name: Checkout branch uses: actions/checkout@v3 @@ -18,16 +19,16 @@ jobs: with: node-version: 18.x - - name: Load Yarn cache - uses: actions/cache@v2 + - name: Restore cached build files + uses: actions/cache@v3 with: - path: ${{ steps.yarn-cache.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- + key: ${{ inputs.nonce }} + path: | + ./components + ./node_modules - name: Install Dependencies - run: yarn install --frozen-lockfile --ignore-engines + run: yarn install env: CI: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 462fe3aa3..ce029ec37 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,22 +1,36 @@ name: Release -on: - push: - branches: - - main -concurrency: - group: release-${{ github.ref }} - cancel-in-progress: true +on: + workflow_call: + inputs: + nonce: + type: string + required: true jobs: release: runs-on: ubuntu-latest steps: - - name: Checkout + - name: Checkout branch uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: 18.x + + - name: Restore cached build files + uses: actions/cache@v3 with: - fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} + key: ${{ inputs.nonce }} + path: | + ./components + ./node_modules + + - name: Install Dependencies + run: yarn install --frozen-lockfile + env: + CI: true - name: Set committer info ## attribute the commit to cypress-bot: https://github.community/t/logging-into-git-as-a-github-app/115916 @@ -24,12 +38,6 @@ jobs: git config --local user.email "${{ secrets.CYPRESS_BOT_APP_ID }}+cypress-bot[bot]@users.noreply.github.com" git config --local user.name "cypress-bot[bot]" - - name: Yarn install - run: yarn install - - - name: Build components - run: yarn build:components - - name: Configure .npmrc run: | cat << EOF > "$HOME/.npmrc" diff --git a/.github/workflows/template-test.yml b/.github/workflows/template-test.yml index 37fae2a3c..3454935f5 100644 --- a/.github/workflows/template-test.yml +++ b/.github/workflows/template-test.yml @@ -1,15 +1,16 @@ name: Template Tests -on: [push] +on: + workflow_call: + inputs: + nonce: + type: string + required: true jobs: template-test: runs-on: ubuntu-latest steps: - - name: Get Yarn cache path - id: yarn-cache - run: echo "::set-output name=dir::$(yarn cache dir)" - - name: Checkout branch uses: actions/checkout@v3 @@ -18,22 +19,17 @@ jobs: with: node-version: 18.x - - name: Load Yarn cache - uses: actions/cache@v2 + - name: Restore cached build files + uses: actions/cache@v3 with: - path: ${{ steps.yarn-cache.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- + key: ${{ inputs.nonce }} + path: | + ./components + ./node_modules - name: Remove Postinstall Script run: npm pkg set scripts.postinstall="echo no-postinstall" - - name: Install Dependencies - run: yarn install --frozen-lockfile - env: - CI: true - - name: Create component with template run: yarn new:component --name ComponentName diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c0788e7ef..6820be3eb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,15 +1,16 @@ name: Tests -on: [push] +on: + workflow_call: + inputs: + nonce: + type: string + required: true jobs: cypress-run: runs-on: ubuntu-latest steps: - - name: Get Yarn cache path - id: yarn-cache - run: echo "::set-output name=dir::$(yarn cache dir)" - - name: Checkout branch uses: actions/checkout@v3 @@ -18,13 +19,13 @@ jobs: with: node-version: 18.x - - name: Load Yarn cache - uses: actions/cache@v2 + - name: Restore cached build files + uses: actions/cache@v3 with: - path: ${{ steps.yarn-cache.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- + key: ${{ inputs.nonce }} + path: | + ./components + ./node_modules - name: Remove Postinstall Script run: npm pkg set scripts.postinstall="echo no-postinstall" diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 000000000..108490c1f --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,76 @@ +name: Workflow + +on: + push: + branches: + - main + pull_request: + types: [opened, reopened, synchronize, ready_for_review] + +concurrency: + group: test-${{ github.ref_name }} + cancel-in-progress: true + +jobs: + make-nonce: + runs-on: ubuntu-latest + outputs: + nonce: ${{ steps.nonce.outputs.nonce }} + steps: + - name: Simplify branch name + id: branch + uses: actions/github-script@v6 + with: + script: | + const simpleBranchName = '${{ github.head_ref }}'.replace(/[^a-zA-Z0-9.-]/g, '').slice(0, 49) + core.setOutput('simpleBranchName', simpleBranchName) + + - name: generate and Set nonce + id: nonce + run: | + echo "nonce=${{ github.run_id }}-${{ github.run_attempt }}-${{ steps.branch.outputs.simpleBranchName }}" >> $GITHUB_OUTPUT + echo "simpleBranchName=${{ steps.branch.outputs.simpleBranchName }}" >> $GITHUB_OUTPUT + + - name: Display + run: echo ${{ toJSON(steps.nonce.outputs.nonce) }} + + build: + name: Build + needs: [make-nonce] + uses: ./.github/workflows/build.yml + secrets: inherit + with: + nonce: ${{ needs.make-nonce.outputs.nonce }} + + test: + name: Test + needs: [build, make-nonce] + uses: ./.github/workflows/test.yml + secrets: inherit + with: + nonce: ${{ needs.make-nonce.outputs.nonce }} + + e2e-test: + name: E2E Test + needs: [build, make-nonce] + uses: ./.github/workflows/e2e-tests.yml + secrets: inherit + with: + nonce: ${{ needs.make-nonce.outputs.nonce }} + + template-test: + name: Template Test + needs: [build, make-nonce] + uses: ./.github/workflows/template-test.yml + secrets: inherit + with: + nonce: ${{ needs.make-nonce.outputs.nonce }} + + release: + name: Release + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + needs: [build, make-nonce, test, e2e-test, template-test] + uses: ./.github/workflows/release.yml + secrets: inherit + with: + nonce: ${{ needs.make-nonce.outputs.nonce }}