diff --git a/.github/workflows/npm-build.yml b/.github/workflows/npm-build.yml new file mode 100644 index 0000000..bd92cbc --- /dev/null +++ b/.github/workflows/npm-build.yml @@ -0,0 +1,115 @@ +# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-FileCopyrightText: 2026 LibreCode coop and contributors +# SPDX-License-Identifier: MIT + +name: Build Javascript + +on: + workflow_call: + +permissions: + contents: read + +concurrency: + group: node-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + changes: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + outputs: + src: ${{ steps.changes.outputs.src }} + steps: + - name: Detect frontend changes + id: changes + uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3 + 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 + needs: changes + if: needs.changes.outputs.src != 'false' + name: NPM build + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Read package.json node and npm engines version + id: versions + uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3 + with: + fallbackNode: '^24' + fallbackNpm: '^11.3' + + - name: Set up node ${{ steps.versions.outputs.nodeVersion }} + uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + with: + node-version: ${{ steps.versions.outputs.nodeVersion }} + + - name: Enforce package engine requirements + run: | + npm --version + npm config set engine-strict true + + - name: Validate package-lock.json + run: | + npm exec --yes --package=npm-package-lock-add-resolved@1.1.4 -- npm-package-lock-add-resolved + git --no-pager diff --exit-code + + - name: Install dependencies and build + env: + CYPRESS_INSTALL_BINARY: 0 + PUPPETEER_SKIP_DOWNLOAD: true + run: | + npm ci + npm run build --if-present + + - name: Check build changes + run: | + if [ -n "$(git status --porcelain)" ]; then + echo 'Please recompile and commit the assets. See the "Show changes on failure" step for details.' + exit 1 + fi + + - name: Show changes on failure + if: failure() + run: | + git status + git --no-pager diff + exit 1 + + summary: + permissions: + contents: none + runs-on: ubuntu-latest + needs: + - changes + - build + if: always() + name: node + steps: + - name: Summary status + env: + CHANGED: ${{ needs.changes.outputs.src }} + BUILD_RESULT: ${{ needs.build.result }} + run: | + if [ "$CHANGED" != "false" ] && [ "$BUILD_RESULT" != "success" ]; then + exit 1 + fi diff --git a/workflow-templates/npm-build.properties.json b/workflow-templates/npm-build.properties.json new file mode 100644 index 0000000..4364d06 --- /dev/null +++ b/workflow-templates/npm-build.properties.json @@ -0,0 +1,11 @@ +{ + "name": "Frontend build", + "description": "Install frontend dependencies, validate the lockfile, build assets and check for uncommitted build changes.", + "iconName": "octicon package", + "categories": [ + "JavaScript" + ], + "filePatterns": [ + "^package.json$" + ] +} diff --git a/workflow-templates/npm-build.properties.json.license b/workflow-templates/npm-build.properties.json.license new file mode 100644 index 0000000..1ce4e0c --- /dev/null +++ b/workflow-templates/npm-build.properties.json.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2026 LibreCode coop and contributors +SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/workflow-templates/npm-build.yml b/workflow-templates/npm-build.yml new file mode 100644 index 0000000..f3029cc --- /dev/null +++ b/workflow-templates/npm-build.yml @@ -0,0 +1,16 @@ +# SPDX-FileCopyrightText: 2026 LibreCode coop and contributors +# SPDX-License-Identifier: AGPL-3.0-or-later + +# This workflow is published through the LibreCode organization catalog. +# Implementation: LibreCodeCoop/github-workflows + +name: Build Javascript + +on: pull_request + +permissions: + contents: read + +jobs: + npm-build: + uses: LibreCodeCoop/github-workflows/.github/workflows/npm-build.yml@bab6f01a48474e6b00feb71882be2f4dafe928fc