Skip to content

Commit

Permalink
ci: update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael M committed Oct 27, 2023
1 parent 34d01b2 commit f1f9c92
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 64 deletions.
82 changes: 82 additions & 0 deletions .github/actions/nodejs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Action for Node.js & cache
description: Node.js setup and cache

inputs:
node-version:
description: Node.js version
required: false
default: 18.x

outputs:
root-package-version:
description: Full version from root package.json
value: ${{ steps.output.outputs.root-package-version }}
root-package-major-version:
description: Major version from root package.json
value: ${{ steps.output.outputs.root-package-major-version }}

runs:
using: composite
steps:
- name: Additional debug logs
shell: bash
run: |
echo "github.workflow: ${{ github.workflow }}"
echo "github.sha: ${{ github.sha }}"
echo "github.ref: ${{ github.ref }}"
echo "github.ref_name: ${{ github.ref_name }}"
echo "github.ref_type: ${{ github.ref_type }}"
echo "github.base_ref: ${{ github.base_ref }}"
echo "github.head_ref: ${{ github.head_ref }}"
echo "github.run_id: ${{ github.run_id }}"
echo "github.run_number: ${{ github.run_number }}"
echo "github.run_attempt: ${{ github.run_attempt }}"
echo "github.event.number: ${{ github.event.number }}"
echo "github.event.pull_request.head.ref: ${{ github.event.pull_request.head.ref }}"
echo "github.event.pull_request.head.repo.full_name: ${{ github.event.pull_request.head.repo.full_name }}"

Check failure

Code scanning / CodeQL

Expression injection in Actions Critical

Potential injection from the ${{ github.head_ref }}, which may be controlled by an external user.
Potential injection from the ${{ github.event.pull_request.head.ref }}, which may be controlled by an external user.
- name: Use Node.js ${{ inputs.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
registry-url: 'https://registry.npmjs.org'

- name: Restore node_modules from cache
id: cache-node-modules
uses: actions/cache@v3
with:
path: |
**/node_modules/
!**/node_modules/.cache
key: modules-cache__nodejs-${{ inputs.node-version }}__${{ hashFiles('package-lock.json') }}

- name: Restore from global npm cache
if: steps.cache-node-modules.outputs.cache-hit != 'true'
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-cache__nodejs-${{ inputs.node-version }}__${{ hashFiles('package-lock.json') }}
restore-keys: npm-cache-hash__

- shell: bash
run: |
echo "Environment info: Node.js, npm"
node -v
npm -v
- shell: bash
run: |
echo "Providing global variables"
echo "TIMING=true" >> $GITHUB_ENV
echo "NPM_CONFIG_CACHE=~/.npm" >> $GITHUB_ENV
- name: Clean install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci
shell: bash

- id: output
shell: bash
run: |
echo "root-package-version=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
echo "root-package-major-version=$(node -p "parseInt(require('./package.json').version)")" >> $GITHUB_OUTPUT
52 changes: 0 additions & 52 deletions .github/actions/setup-node/action.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node.js and cache
uses: ./.github/actions/setup-node
uses: ./.github/actions/nodejs

- name: Build only changed packages
if: ${{ env.IS_MAIN == 'false' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
security-events: write
steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ jobs:
steps:
- name: Checkout origin repo
if: ${{ env.IS_FORK == 'false' && env.IS_DBOT == 'false' }}
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.BM_GITHUB_PAT }}
fetch-depth: 2
- name: Checkout forked repo
if: ${{ env.IS_FORK == 'true' || env.IS_DBOT == 'true' }}
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Setup Node.js and cache
uses: ./.github/actions/setup-node
uses: ./.github/actions/nodejs

#- name: Typecheck
# run: npm run typecheck
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.BM_GITHUB_PAT }}
fetch-depth: 0

- name: Setup Node.js and cache
uses: ./.github/actions/setup-node
uses: ./.github/actions/nodejs

- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v4
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
name: Any test with nx
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node.js and cache
uses: ./.github/actions/setup-node
uses: ./.github/actions/nodejs

- name: Test all packages
run: npm run ci:all:test
Expand All @@ -32,14 +32,14 @@ jobs:
coverage-reports: 'coverage/packages/*/lcov.info'

- name: Report to Code Climate
uses: paambaati/codeclimate-action@v3.0.0
uses: paambaati/codeclimate-action@v3.2.0
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageLocations: 'coverage/packages/*/lcov.info:lcov'

- name: Report to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: 'coverage/packages/*/lcov.info'
Expand Down

0 comments on commit f1f9c92

Please sign in to comment.