From efbf5cb6c1d570e91536148404f35a5e7b0a3421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Tue, 26 Dec 2023 15:04:45 +0100 Subject: [PATCH 1/2] chore: update workflows from templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- .github/workflows/cypress.yml | 130 ++++++++++++++++++++++------ .github/workflows/documentation.yml | 10 ++- .github/workflows/node-test.yml | 91 +++++++++++++------ .github/workflows/node.yml | 72 ++++++++++----- .github/workflows/npm-publish.yml | 26 +++++- 5 files changed, 248 insertions(+), 81 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index f4714b60..42e64899 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -1,69 +1,147 @@ name: Cypress -on: - pull_request: - push: - branches: - - main - - master - - stable* +on: pull_request + +concurrency: + group: cypress-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +env: + # Adjust APP_NAME if your repository name is different + APP_NAME: ${{ github.event.repository.name }} + + # This represents the server branch to checkout. + # Usually it's the base branch of the PR, but for pushes it's the branch itself. + # e.g. 'main', 'stable27' or 'feature/my-feature + # n.b. server will use head_ref, as we want to test the PR branch. + BRANCH: ${{ github.base_ref || github.ref_name }} jobs: - cypress: + init: runs-on: ubuntu-latest + outputs: + nodeVersion: ${{ steps.versions.outputs.nodeVersion }} + npmVersion: ${{ steps.versions.outputs.npmVersion }} - strategy: - fail-fast: false - matrix: - # run multiple copies of the current job in parallel - containers: [1] + env: + PUPPETEER_SKIP_DOWNLOAD: true - name: runner ${{ matrix.containers }} steps: - name: Checkout app uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Check composer.json + id: check_composer + uses: andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2 + with: + files: "composer.json" + + - name: Install composer dependencies + if: steps.check_composer.outputs.files_exists == 'true' + run: composer install --no-dev + - name: Read package.json node and npm engines version - uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.1 + uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.2 id: versions with: fallbackNode: "^20" fallbackNpm: "^9" - name: Set up node ${{ steps.versions.outputs.nodeVersion }} - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0 with: - cache: 'npm' node-version: ${{ steps.versions.outputs.nodeVersion }} - name: Set up npm ${{ steps.versions.outputs.npmVersion }} run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}" - - name: Build and run Cypress + - name: Install node dependencies & build app + run: | + npm ci + TESTING=true npm run build --if-present + + - name: Save context + uses: buildjet/cache/save@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3 + with: + key: cypress-context-${{ github.run_id }} + path: ./ + + cypress: + runs-on: ubuntu-latest + needs: init + + strategy: + fail-fast: false + matrix: + # Run multiple copies of the current job in parallel + # Please increase the number or runners as your tests suite grows + containers: ["component", 1, 2, 3] + + name: runner ${{ matrix.containers }} + + steps: + - name: Restore context + uses: buildjet/cache/restore@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3 + with: + fail-on-cache-miss: true + key: cypress-context-${{ github.run_id }} + path: ./ + + - name: Set up node ${{ needs.init.outputs.nodeVersion }} + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0 + with: + node-version: ${{ needs.init.outputs.nodeVersion }} + + - name: Set up npm ${{ needs.init.outputs.npmVersion }} + run: npm i -g npm@"${{ needs.init.outputs.npmVersion }}" + + - name: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} cypress tests uses: cypress-io/github-action@ebe8b24c4428922d0f793a5c4c96853a633180e3 # v6.6.0 with: - build: npm run build - component: true - # cypress io record: true parallel: true + # cypress run type + component: ${{ matrix.containers == 'component' }} + group: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} # cypress env ci-build-id: ${{ github.sha }}-${{ github.run_number }} tag: ${{ github.event_name }} env: + # Needs to be prefixed with CYPRESS_ + CYPRESS_BRANCH: ${{ env.BRANCH }} # https://github.com/cypress-io/github-action/issues/124 - COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }} + COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }} + # Needed for some specific code workarounds + TESTING: true GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - npm_package_name: nextcloud-upload - npm_package_version: cypress + + - name: Upload snapshots + uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0 + if: always() + with: + name: snapshots_${{ matrix.containers }} + path: cypress/snapshots + + - name: Extract NC logs + if: failure() && matrix.containers != 'component' + run: docker logs nextcloud-cypress-tests-${{ env.APP_NAME }} > nextcloud.log + + - name: Upload NC logs + uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0 + if: failure() && matrix.containers != 'component' + with: + name: nc_logs_${{ matrix.containers }} + path: nextcloud.log summary: runs-on: ubuntu-latest - needs: cypress + needs: [init, cypress] + if: always() name: cypress-summary + steps: - name: Summary status - run: if ${{ needs.cypress.result != 'success' && needs.cypress.result != 'skipped' }}; then exit 1; fi + run: if ${{ needs.init.result != 'success' || ( needs.cypress.result != 'success' && needs.cypress.result != 'skipped' ) }}; then exit 1; fi diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 093f7739..c886f402 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -22,14 +22,14 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Read package.json node and npm engines version - uses: skjnldsv/read-package-engines-version-actions@v2.2 # v2.2 + uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.2 id: versions with: - fallbackNode: '^16' - fallbackNpm: '^8' + fallbackNode: '^20' + fallbackNpm: '^9' - name: Set up node ${{ steps.versions.outputs.nodeVersion }} - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0 with: node-version: ${{ steps.versions.outputs.nodeVersion }} @@ -37,6 +37,8 @@ jobs: run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}" - name: Install dependencies & build + env: + CYPRESS_INSTALL_BINARY: 0 run: | npm ci npm run build --if-present diff --git a/.github/workflows/node-test.yml b/.github/workflows/node-test.yml index ad185389..43a19ed2 100644 --- a/.github/workflows/node-test.yml +++ b/.github/workflows/node-test.yml @@ -1,4 +1,4 @@ -name: Node +name: Node tests on: pull_request: @@ -8,51 +8,92 @@ on: - master - stable* +permissions: + contents: read + +concurrency: + group: node-tests-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + jobs: + changes: + runs-on: ubuntu-latest + + outputs: + src: ${{ steps.changes.outputs.src}} + + steps: + - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - '__tests__/**' + - '__mocks__/**' + - 'src/**' + - 'appinfo/info.xml' + - 'package.json' + - 'package-lock.json' + - 'tsconfig.json' + - '**.js' + - '**.ts' + - '**.vue' + test: runs-on: ubuntu-latest - permissions: - checks: write - pull-requests: write - strategy: - matrix: - node-version: [ 16, 18, 20 ] - include: - - node-version: 16 - coverage: coverage - - name: test + + needs: changes + if: needs.changes.outputs.src != 'false' + steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Read package.json node and npm engines version + uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.2 + id: versions + with: + fallbackNode: '^20' + fallbackNpm: '^9' - - name: Set up node ${{ matrix.node-version }} - uses: actions/setup-node@v4.0.1 + - name: Set up node ${{ steps.versions.outputs.nodeVersion }} + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0 with: - node-version: ${{ matrix.node-version }} + node-version: ${{ steps.versions.outputs.nodeVersion }} - - name: Install dependencies - run: npm ci + - name: Set up npm ${{ steps.versions.outputs.npmVersion }} + run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}" + + - name: Install dependencies & build + env: + CYPRESS_INSTALL_BINARY: 0 + run: | + npm ci + npm run build --if-present - name: Test run: npm run test --if-present - name: Test and process coverage - if: matrix.coverage - run: npm run test:coverage - + run: npm run test:coverage --if-present + - name: Collect coverage - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 with: files: ./coverage/lcov.info - summary: + permissions: + contents: none runs-on: ubuntu-latest - needs: test + needs: [changes, test] + if: always() name: test-summary + steps: - name: Summary status - run: if ${{ needs.test.result != 'success' && needs.test.result != 'skipped' }}; then exit 1; fi + run: if ${{ needs.changes.outputs.src != 'false' && needs.test.result != 'success' }}; then exit 1; fi diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index 8088f041..75c32b44 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -5,23 +5,7 @@ name: Node -on: - pull_request: - paths: - - '.github/workflows/**' - - 'src/**' - - 'appinfo/info.xml' - - 'package.json' - - 'package-lock.json' - - 'tsconfig.json' - - '**.js' - - '**.ts' - - '**.vue' - push: - branches: - - main - - master - - stable* +on: pull_request permissions: contents: read @@ -31,23 +15,49 @@ concurrency: cancel-in-progress: true jobs: + changes: + runs-on: ubuntu-latest + + outputs: + src: ${{ steps.changes.outputs.src}} + + steps: + - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'src/**' + - 'appinfo/info.xml' + - 'package.json' + - 'package-lock.json' + - 'tsconfig.json' + - '**.js' + - '**.ts' + - '**.vue' + build: runs-on: ubuntu-latest - name: node + needs: changes + if: needs.changes.outputs.src != 'false' + + name: NPM build steps: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Read package.json node and npm engines version - uses: skjnldsv/read-package-engines-version-actions@v2.2 # v2.1 + uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.2 id: versions with: - fallbackNode: '^16' - fallbackNpm: '^7' + fallbackNode: '^20' + fallbackNpm: '^9' - name: Set up node ${{ steps.versions.outputs.nodeVersion }} - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v3 + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v3 with: node-version: ${{ steps.versions.outputs.nodeVersion }} @@ -55,6 +65,9 @@ jobs: run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}" - name: Install dependencies & build + env: + CYPRESS_INSTALL_BINARY: 0 + PUPPETEER_SKIP_DOWNLOAD: true run: | npm ci npm run build --if-present @@ -69,3 +82,18 @@ jobs: git status git --no-pager diff exit 1 # make it red to grab attention + + summary: + permissions: + contents: none + runs-on: ubuntu-latest + needs: [changes, build] + + if: always() + + # This is the summary, we just avoid to rename it so that branch protection rules still match + name: node + + steps: + - name: Summary status + run: if ${{ needs.changes.outputs.src != 'false' && needs.build.result != 'success' }}; then exit 1; fi diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 6611f6df..1e234f8a 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -11,6 +11,7 @@ on: permissions: contents: read + packages: write jobs: publish: @@ -18,18 +19,23 @@ jobs: name: Build and publish to npm steps: + - name: Check actor permission level + uses: skjnldsv/check-actor-permission@e591dbfe838300c007028e1219ca82cc26e8d7c5 # v2.1 + with: + require: admin + - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Read package.json node and npm engines version - uses: skjnldsv/read-package-engines-version-actions@v2.2 # v2.1 + uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.2 id: versions with: - fallbackNode: '^16' - fallbackNpm: '^7' + fallbackNode: '^20' + fallbackNpm: '^9' - name: Set up node ${{ steps.versions.outputs.nodeVersion }} - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v3 + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v3 with: node-version: ${{ steps.versions.outputs.nodeVersion }} @@ -37,6 +43,8 @@ jobs: run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}" - name: Install dependencies & build + env: + CYPRESS_INSTALL_BINARY: 0 run: | npm ci npm run build --if-present @@ -47,3 +55,13 @@ jobs: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Setup Github Package Registry + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v3 + with: + registry-url: 'https://npm.pkg.github.com' + + - name: Publish package on GPR + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From b4a6b9e23b715247068d3a154632f5a983e2072d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Wed, 10 Jan 2024 17:31:41 +0100 Subject: [PATCH 2/2] Discard changes to .github/workflows/cypress.yml --- .github/workflows/cypress.yml | 130 +++++++--------------------------- 1 file changed, 26 insertions(+), 104 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 42e64899..f4714b60 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -1,147 +1,69 @@ name: Cypress -on: pull_request - -concurrency: - group: cypress-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -env: - # Adjust APP_NAME if your repository name is different - APP_NAME: ${{ github.event.repository.name }} - - # This represents the server branch to checkout. - # Usually it's the base branch of the PR, but for pushes it's the branch itself. - # e.g. 'main', 'stable27' or 'feature/my-feature - # n.b. server will use head_ref, as we want to test the PR branch. - BRANCH: ${{ github.base_ref || github.ref_name }} +on: + pull_request: + push: + branches: + - main + - master + - stable* jobs: - init: + cypress: runs-on: ubuntu-latest - outputs: - nodeVersion: ${{ steps.versions.outputs.nodeVersion }} - npmVersion: ${{ steps.versions.outputs.npmVersion }} - env: - PUPPETEER_SKIP_DOWNLOAD: true + strategy: + fail-fast: false + matrix: + # run multiple copies of the current job in parallel + containers: [1] + name: runner ${{ matrix.containers }} steps: - name: Checkout app uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - name: Check composer.json - id: check_composer - uses: andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2 - with: - files: "composer.json" - - - name: Install composer dependencies - if: steps.check_composer.outputs.files_exists == 'true' - run: composer install --no-dev - - name: Read package.json node and npm engines version - uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.2 + uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.1 id: versions with: fallbackNode: "^20" fallbackNpm: "^9" - name: Set up node ${{ steps.versions.outputs.nodeVersion }} - uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0 + uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 with: + cache: 'npm' node-version: ${{ steps.versions.outputs.nodeVersion }} - name: Set up npm ${{ steps.versions.outputs.npmVersion }} run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}" - - name: Install node dependencies & build app - run: | - npm ci - TESTING=true npm run build --if-present - - - name: Save context - uses: buildjet/cache/save@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3 - with: - key: cypress-context-${{ github.run_id }} - path: ./ - - cypress: - runs-on: ubuntu-latest - needs: init - - strategy: - fail-fast: false - matrix: - # Run multiple copies of the current job in parallel - # Please increase the number or runners as your tests suite grows - containers: ["component", 1, 2, 3] - - name: runner ${{ matrix.containers }} - - steps: - - name: Restore context - uses: buildjet/cache/restore@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3 - with: - fail-on-cache-miss: true - key: cypress-context-${{ github.run_id }} - path: ./ - - - name: Set up node ${{ needs.init.outputs.nodeVersion }} - uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0 - with: - node-version: ${{ needs.init.outputs.nodeVersion }} - - - name: Set up npm ${{ needs.init.outputs.npmVersion }} - run: npm i -g npm@"${{ needs.init.outputs.npmVersion }}" - - - name: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} cypress tests + - name: Build and run Cypress uses: cypress-io/github-action@ebe8b24c4428922d0f793a5c4c96853a633180e3 # v6.6.0 with: + build: npm run build + component: true + # cypress io record: true parallel: true - # cypress run type - component: ${{ matrix.containers == 'component' }} - group: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} # cypress env ci-build-id: ${{ github.sha }}-${{ github.run_number }} tag: ${{ github.event_name }} env: - # Needs to be prefixed with CYPRESS_ - CYPRESS_BRANCH: ${{ env.BRANCH }} # https://github.com/cypress-io/github-action/issues/124 - COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }} - # Needed for some specific code workarounds - TESTING: true + COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - - - name: Upload snapshots - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0 - if: always() - with: - name: snapshots_${{ matrix.containers }} - path: cypress/snapshots - - - name: Extract NC logs - if: failure() && matrix.containers != 'component' - run: docker logs nextcloud-cypress-tests-${{ env.APP_NAME }} > nextcloud.log - - - name: Upload NC logs - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0 - if: failure() && matrix.containers != 'component' - with: - name: nc_logs_${{ matrix.containers }} - path: nextcloud.log + npm_package_name: nextcloud-upload + npm_package_version: cypress summary: runs-on: ubuntu-latest - needs: [init, cypress] - + needs: cypress if: always() name: cypress-summary - steps: - name: Summary status - run: if ${{ needs.init.result != 'success' || ( needs.cypress.result != 'success' && needs.cypress.result != 'skipped' ) }}; then exit 1; fi + run: if ${{ needs.cypress.result != 'success' && needs.cypress.result != 'skipped' }}; then exit 1; fi