Skip to content

Commit

Permalink
chore: update workflows from templates
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed Feb 5, 2024
1 parent d4f4947 commit d050c79
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 229 deletions.
265 changes: 71 additions & 194 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,269 +2,146 @@ name: Cypress

on: pull_request

permissions:
contents: read

concurrency:
group: cypress-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
APP_NAME: collectives
CYPRESS_baseUrl: http://localhost:8081/index.php

jobs:
changes:
runs-on: ubuntu-latest
# Adjust APP_NAME if your repository name is different
APP_NAME: ${{ github.event.repository.name }}

outputs:
src: ${{ steps.changes.outputs.src}}

steps:
- uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
id: changes
continue-on-error: true
with:
filters: |
src:
- '.github/workflows/**'
- 'appinfo/**'
- 'css/**'
- 'lib/**'
- 'skeleton/**'
- 'src/**'
- 'templates/**'
- 'babel.config.js'
- 'composer.json'
- 'composer.lock'
- 'cypress.config.js'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
- '**.js'
- '**.ts'
- '**.vue'
# 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:
init:
runs-on: ubuntu-22.04

needs: changes
if: needs.changes.outputs.src != 'false'

runs-on: ubuntu-latest
outputs:
nodeVersion: ${{ steps.versions.outputs.nodeVersion }}
npmVersion: ${{ steps.versions.outputs.npmVersion }}

strategy:
matrix:
server-versions: ['stable27', 'master']
env:
PUPPETEER_SKIP_DOWNLOAD: true

steps:
- name: Checkout server
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: true
repository: nextcloud/server
ref: ${{ matrix.server-versions }}

- name: Checkout circles app
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
repository: nextcloud/circles
path: apps/circles
ref: ${{ matrix.server-versions }}

- name: Checkout files_pdfviewer app
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
repository: nextcloud/files_pdfviewer
path: apps/files_pdfviewer
ref: ${{ matrix.server-versions }}

- name: Register text Git reference
run: |
text_app_ref="$(if [ "${{ matrix.server-versions }}" = "master" ]; then echo -n "main"; else echo -n "${{ matrix.server-versions }}"; fi)"
echo "text_app_ref=$text_app_ref" >> $GITHUB_ENV
- name: Checkout text app
- name: Checkout app
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
repository: nextcloud/text
path: apps/text
ref: ${{ env.text_app_ref }}

- name: Checkout viewer app
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Check composer.json
id: check_composer
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v2
with:
repository: nextcloud/viewer
path: apps/viewer
ref: ${{ matrix.server-versions }}
files: "composer.json"

- name: Checkout app
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
path: apps/${{ env.APP_NAME }}
- 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
id: versions
with:
fallbackNode: '^20'
fallbackNpm: '^9'
path: apps/${{ env.APP_NAME }}
fallbackNode: "^20"
fallbackNpm: "^10"

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v3
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 dependencies & build
working-directory: apps/${{ env.APP_NAME }}
- name: Install node dependencies & build app
run: |
npm ci
npm run build --if-present
TESTING=true npm run build --if-present
- name: Save context
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
uses: buildjet/cache/save@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
with:
key: cypress-context-${{ matrix.server-versions }}-${{ github.run_id }}
key: cypress-context-${{ github.run_id }}
path: ./

cypress:
runs-on: ubuntu-22.04

needs: [changes, init]
if: needs.changes.outputs.src != 'false'
runs-on: ubuntu-latest
needs: init

strategy:
fail-fast: false
matrix:
node-version: [20]
containers: [1, 2, 3]
php-versions: ['8.0', '8.2']
databases: ['sqlite']
server-versions: ['stable27', 'master']
# Only use cypress cloud for PRs
use-cypress-cloud:
- ${{ vars.USE_CYPRESS_CLOUD && !!github.head_ref }}
exclude:
- php-versions: '8.0'
server-versions: 'stable27'
- php-versions: '8.0'
server-versions: 'master'
# Only use one container if we are not using the cypress cloud.
- use-cypress-cloud: false
containers: 2
- use-cypress-cloud: false
containers: 3
# 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: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
uses: buildjet/cache/restore@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
with:
fail-on-cache-miss: true
key: cypress-context-${{ matrix.server-versions }}-${{ github.run_id }}
key: cypress-context-${{ github.run_id }}
path: ./

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v3
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: Set up php ${{ matrix.php-versions }}
uses: shivammathur/setup-php@6d7209f44a25a59e904b1ee9f3b0c33ab2cd888d # v2
- name: Set up node ${{ needs.init.outputs.nodeVersion }}
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
with:
php-version: ${{ matrix.php-versions }}
# https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite
coverage: none
ini-file: development
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install composer dependencies
working-directory: apps/${{ env.APP_NAME }}
run: composer i --no-dev

- name: Set up Nextcloud
env:
DB_PORT: 4444
run: |
mkdir data
./occ maintenance:install --verbose --database=sqlite --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
./occ config:system:set --value="http://localhost:8081" -- overwrite.cli.url
./occ app:enable --force contacts
./occ app:enable --force files_pdfviewer
./occ app:enable --force ${{ env.APP_NAME }}
node-version: ${{ needs.init.outputs.nodeVersion }}

- name: Run Nextcloud
run: php -S 0.0.0.0:8081 &
env:
PHP_CLI_SERVER_WORKERS: 3

- name: Add Nextcloud users and a collective for full-text search
run: |
for user in alice bob jane john; do \
OC_PASS="$user" ./occ user:add --password-from-env "$user"; \
done
./occ group:add "Bobs Group"
for user in bob jane; do \
OC_PASS="$user" ./occ group:adduser "Bobs Group" "$user"; \
done
./occ collectives:create SearchTest --owner=bob
./occ collectives:index
- name: Set up npm ${{ needs.init.outputs.npmVersion }}
run: npm i -g npm@"${{ needs.init.outputs.npmVersion }}"

- name: Cypress run
uses: cypress-io/github-action@v6
- name: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} cypress tests
uses: cypress-io/github-action@1b70233146622b69e789ccdd4f9452adc638d25a # v6.6.1
with:
record: '${{ !!matrix.use-cypress-cloud }}'
parallel: '${{ !!matrix.use-cypress-cloud }}'
group: "${{ !!matrix.use-cypress-cloud && format('Nextcloud {0}', matrix.server-versions) || '' }}"
wait-on: '${{ env.CYPRESS_baseUrl }}'
working-directory: apps/${{ env.APP_NAME }}
config: video=false,defaultCommandTimeout=20000
tag: "${{ !!matrix.use-cypress-cloud && github.event_name || '' }}"
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_SHA: ${{ github.event.pull_request.head.sha }}
# Needed for some specific code workarounds
TESTING: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
CYPRESS_ncVersion: ${{ matrix.server-versions }}

- name: Upload test failure screenshots
uses: actions/upload-artifact@v4
if: failure()
- name: Upload snapshots
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
if: always()
with:
name: Screenshots.${{ matrix.server-versions }}-${{ matrix.containers }}
path: apps/${{ env.APP_NAME }}/cypress/screenshots/
retention-days: 5
name: snapshots_${{ matrix.containers }}
path: cypress/snapshots

- name: Upload nextcloud logs
uses: actions/upload-artifact@v4
if: always()
- 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@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
if: failure() && matrix.containers != 'component'
with:
name: ${{ matrix.server-versions }}-${{ matrix.containers }}.log
path: data/nextcloud.log
retention-days: 5
name: nc_logs_${{ matrix.containers }}
path: nextcloud.log

summary:
permissions:
contents: none
runs-on: ubuntu-latest
needs: [changes, init, cypress]
needs: [init, cypress]

if: always()

name: cypress-summary

steps:
- name: Summary status
run: if ${{ needs.changes.outputs.src != 'false' && (needs.init.result != 'success' || ( 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
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-approve-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ concurrency:
jobs:
auto-approve-merge:
if: github.actor == 'dependabot[bot]'
runs-on: ubuntu-latest
runs-on: ubuntu-latest-low
permissions:
# for hmarr/auto-approve-action to approve PRs
pull-requests: write
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint-eslint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ concurrency:

jobs:
changes:
runs-on: ubuntu-latest
runs-on: ubuntu-latest-low

outputs:
src: ${{ steps.changes.outputs.src}}
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
id: versions
with:
fallbackNode: '^20'
fallbackNpm: '^9'
fallbackNpm: '^10'

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v3
Expand All @@ -82,7 +82,7 @@ jobs:
summary:
permissions:
contents: none
runs-on: ubuntu-latest
runs-on: ubuntu-latest-low
needs: [changes, lint]

if: always()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-info-xml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ concurrency:

jobs:
xml-linters:
runs-on: ubuntu-latest
runs-on: ubuntu-latest-low

name: info.xml lint
steps:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/lint-php-cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
uses: shivammathur/setup-php@6d7209f44a25a59e904b1ee9f3b0c33ab2cd888d # v2
with:
php-version: 8.2
# https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite
coverage: none
ini-file: development
Expand Down
Loading

0 comments on commit d050c79

Please sign in to comment.