From 23c52c3170795dc9579ca966a3ce33f43ad6950d Mon Sep 17 00:00:00 2001 From: Yaroslav Grishajev Date: Wed, 17 Apr 2024 13:27:44 +0200 Subject: [PATCH] adds more CI validations, introduces semantic release (#74) --- ...t-reusable.yml => code-style-reusable.yml} | 5 +- .github/workflows/code-style.yml | 10 ++++ .github/workflows/commit-lint.yml | 6 +- .github/workflows/lint.yml | 9 --- .github/workflows/release.yml | 57 ++++++++++--------- .github/workflows/test-reusable.yml | 3 +- .github/workflows/test.yml | 3 +- 7 files changed, 51 insertions(+), 42 deletions(-) rename .github/workflows/{lint-reusable.yml => code-style-reusable.yml} (95%) create mode 100644 .github/workflows/code-style.yml delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint-reusable.yml b/.github/workflows/code-style-reusable.yml similarity index 95% rename from .github/workflows/lint-reusable.yml rename to .github/workflows/code-style-reusable.yml index 169ac02..fcbe012 100644 --- a/.github/workflows/lint-reusable.yml +++ b/.github/workflows/code-style-reusable.yml @@ -1,4 +1,4 @@ -name: Lint +name: Code Style on: - workflow_call @@ -29,7 +29,8 @@ jobs: if: needs.duplicate-check.outputs.should_skip != 'true' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 - name: Setup Node.js id: setup_node diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml new file mode 100644 index 0000000..669e50f --- /dev/null +++ b/.github/workflows/code-style.yml @@ -0,0 +1,10 @@ +name: Code Style + +on: + - pull_request + +jobs: + code-style: + name: Code Style + uses: ./.github/workflows/code-style-reusable.yml + secrets: inherit diff --git a/.github/workflows/commit-lint.yml b/.github/workflows/commit-lint.yml index bc13bfa..8b432c5 100644 --- a/.github/workflows/commit-lint.yml +++ b/.github/workflows/commit-lint.yml @@ -1,10 +1,10 @@ -name: Commit Lint Feature Check +name: Commit Lint on: - pull_request jobs: commit-lint: - name: Main - uses: ./.github/workflows/commit-lint-reusable.yml + name: Commit Lint + uses: ./.github/workflows/commit-code-style-reusable.yml secrets: inherit \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 31da81f..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: Lint - -on: - - pull_request - -jobs: - test: - name: Lint - uses: ./.github/workflows/lint-reusable.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9aa1d8e..698d14b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,7 +6,7 @@ on: - main concurrency: - group: ${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true env: @@ -14,49 +14,54 @@ env: jobs: commit-lint: - name: Main - uses: ./.github/workflows/commit-lint-reusable.yml + name: Commit Lint + uses: ./.github/workflows/commit-code-style-reusable.yml + secrets: inherit + + lint: + name: Lint and report coverage + uses: ./.github/workflows/code-style-reusable.yml + secrets: inherit + + test: + name: Run tests + uses: ./.github/workflows/test-reusable.yml secrets: inherit release: name: Build and release npm package - needs: commit-lint + needs: [commit-lint, lint, test] runs-on: ubuntu-latest steps: - - uses: actions/checkout@master - with: - ref: main - - - name: Fetch other branches for commitlint - run: git fetch --prune --unshallow + - name: Checkout + uses: actions/checkout@v4 - name: Setup Node.js - if: steps.changes.outputs.ts == 'true' + id: setup_node uses: actions/setup-node@v4 with: - node-version: 18.0.0 - cache: npm + node-version: 18.0.0 + + - name: Restore node_modules cache + id: deps-cache + uses: martijnhols/actions-cache/restore@v3 + with: + path: node_modules + key: ${{ runner.os }}-build-ts-deps-cache-${{ hashFiles('ts/package-lock.json') }} - name: Install dependencies + if: steps.deps-cache.outputs.cache-hit != 'true' run: npm install - - name: Validate PR commits with commitlint - uses: wagoid/commitlint-github-action@v6 - - - name: Lint - run: npm run lint - - - name: Test - run: npm run test:cov - - name: Release npm package uses: cycjimmy/semantic-release-action@v4 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - name: Upload Test Coverage - uses: codecov/codecov-action@v4 + - name: Cache node modules + if: steps.deps-cache.outputs.cache-hit != 'true' + uses: martijnhols/actions-cache/save@v3 with: - files: ./ts/coverage - token: ${{ secrets.CODECOV_TOKEN }} + path: node_modules + key: ${{ runner.os }}-build-ts-deps-cache-${{ hashFiles('ts/package-lock.json') }} diff --git a/.github/workflows/test-reusable.yml b/.github/workflows/test-reusable.yml index 9b31112..d53c3a9 100644 --- a/.github/workflows/test-reusable.yml +++ b/.github/workflows/test-reusable.yml @@ -29,7 +29,8 @@ jobs: if: needs.duplicate-check.outputs.should_skip != 'true' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 - name: Setup Node.js id: setup_node diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6f382bb..6582a59 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,5 +5,6 @@ on: jobs: test: - name: Test and report coverage + name: Test uses: ./.github/workflows/test-reusable.yml + secrets: inherit