From 6acedb086878d2598d452989d6b910303ecd5a51 Mon Sep 17 00:00:00 2001 From: Louis Grasset Date: Wed, 18 Oct 2023 09:15:03 +0200 Subject: [PATCH] ci: add jobs deps, add build & docker steps, add npm cache --- .github/workflows/ci.yml | 92 ++++++++++++++++++++++++++++++++++++++ .github/workflows/lint.yml | 48 -------------------- 2 files changed, 92 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1629261 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,92 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + +jobs: + commitlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '18.x' + cache: 'npm' + + - name: Install dependencies (with dev) + run: npm ci --include=dev + + - name: Validate current commit (last commit) with commitlint + run: npx commitlint --from HEAD~1 --to HEAD --verbose + + - name: Validate PR commits with commitlint + if: github.event_name == 'pull_request' + run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose + + eslint: + needs: + - commitlint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '18.x' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run Eslint + run: npm run lint + + build: + needs: + - eslint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '18.x' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Build from source + run: npm run build + + docker: + needs: + - build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image + uses: docker/build-push-action@v5 + with: + context: "{{defaultContext}}" + push: ${{ github.event_name != 'pull_request' }} # Don't push on PR + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 81c829c..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Linters Validation - -on: - push: - branches: - - main - pull_request: - -jobs: - commitlint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Use Node.js - uses: actions/setup-node@v3 - with: - node-version: '18.x' - - - name: Install dev dependencies - run: npm i --only=dev - - - name: Validate current commit (last commit) with commitlint - if: github.event_name == 'push' - run: npx commitlint --from HEAD~1 --to HEAD --verbose - - - name: Validate PR commits with commitlint - if: github.event_name == 'pull_request' - run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose - - eslint: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Use Node.js - uses: actions/setup-node@v3 - with: - node-version: '18.x' - - - name: Install dependencies - run: npm ci - - - name: Run Eslint - run: npm run lint