diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml new file mode 100644 index 000000000..f66091c76 --- /dev/null +++ b/.github/actions/setup-node/action.yml @@ -0,0 +1,36 @@ +# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) +# +# SPDX-License-Identifier: AGPL-3.0-only + +name: Setup Node +description: "Setups node and configures the cache" + +inputs: + NODEJS_VERSION: + required: true + description: "NodeJS version to install" + +runs: + using: "composite" + steps: + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + shell: bash + + - name: Cache yarn cache + uses: actions/cache@6998d139ddd3e68c71e9e398d8e40b71a2f39812 # v3.2.5 + id: yarn-cache + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-master + + - name: Set up NodeJS + uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 + with: + node-version: ${{ inputs.NODEJS_VERSION }} + + - name: Install dependencies + run: yarn install --frozen-lockfile --prefer-offline + working-directory: . + shell: bash diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 000000000..f40c4605f --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,43 @@ +name: Build & run tests + +on: + push: + branches: [master] + pull_request: + branches: [master] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.job }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + node: ['14', '16'] + name: Node ${{ matrix.node }} + steps: + - name: Checkout repository + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + + - name: Setup Node + uses: ./.github/actions/setup-node + with: + NODEJS_VERSION: ${{ matrix.node }} + + - name: Build project + run: yarn run build + + - name: Run tests + run: yarn run mocha-suite + + - name: Upload build artifacts + uses: actions/upload-artifact@v3 + if: github.ref == 'refs/heads/master' && matrix.node-version == '16' + with: + name: Prebuild with Node.js ${{ matrix.node-version }} + path: | + ** + !.git + !node_modules diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..ed0a9623e --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,32 @@ +name: Lint + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + lint: + runs-on: ubuntu-latest + name: Lint files + steps: + - name: Checkout repository + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + + - name: Setup node + uses: ./.github/actions/setup-node + with: + NODEJS_VERSION: '16' + + - name: Run ESLint + run: yarn run eslint + + - name: Lint markdown files + run: yarn run markdownlint + + - name: Lint shell scripts with shellcheck + run: shellcheck bin/heroku bin/setup + + - name: Lint JSON files + run: sudo apt install -y jq && yarn run jsonlint diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml deleted file mode 100644 index 2d5bfc9e2..000000000 --- a/.github/workflows/node.js.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: Node.js CI - -on: - push: - branches: [master] - pull_request: - branches: [master] - -jobs: - static-tests: - runs-on: ubuntu-latest - strategy: - matrix: - command: - - yarn run eslint - - yarn run markdownlint - - shellcheck bin/heroku bin/setup - - sudo apt install -y jq && yarn run jsonlint - steps: - - uses: actions/checkout@v3 - - name: Use Node.js 16 - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: yarn - - run: yarn --frozen-lockfile --prefer-offline - - run: ${{matrix.command}} - dynamic-tests: - needs: static-tests - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [14, 16] - steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: yarn - - run: yarn --frozen-lockfile --prefer-offline - - run: yarn run mocha-suite - production-build: - needs: dynamic-tests - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [14, 16] - steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: yarn - - run: yarn --frozen-lockfile --prefer-offline - - run: yarn run build - - uses: actions/upload-artifact@v3 - if: github.ref == 'refs/heads/master' && matrix.node-version == '16' - with: - name: Prebuild with Node.js ${{ matrix.node-version }} - path: | - ** - !.git - !node_modules