diff --git a/.github/actions/nodejs/action.yml b/.github/actions/nodejs/action.yml new file mode 100644 index 0000000..5c64573 --- /dev/null +++ b/.github/actions/nodejs/action.yml @@ -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 }}" + + - 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 diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml deleted file mode 100644 index 2b9b831..0000000 --- a/.github/actions/setup-node/action.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: 'Setup Node.js and cache' -description: 'Setup a Node.js environment & dependencies cache' - -inputs: - node-version: - description: 'Node.js version' - required: false - default: '16.x' - -runs: - using: composite - steps: - - name: Setup Node.js v${{ inputs.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ inputs.node-version }} - registry-url: 'https://registry.npmjs.org' - - - name: Check node modules cache - id: locate-cache - uses: actions/cache@v2 - with: - path: | - node_modules - */*/node_modules/ - !node_modules/.cache - !*/*/node_modules/.cache - key: node-modules-cache-hash__${{ hashfiles('package-lock.json') }} - - - name: Restore node modules from cache - id: build-cache - if: steps.locate-cache.outputs.cache-hit == 'true' - uses: actions/cache@v2 - with: - path: | - node_modules/.cache - */*/node_modules/.cache - key: builds-cache-hash__${{ hashFiles('package-lock.json') }}-${{ github.ref }} - restore-keys: builds-cache-hash__${{ hashFiles('package-lock.json') }} - - - name: Fetch node modules to cache - if: steps.locate-cache.outputs.cache-hit != 'true' - uses: actions/cache@v2 - with: - path: ~/.npm - key: npm-cache-hash__${{ hashFiles('package-lock.json') }} - restore-keys: npm-cache-hash__ - - - name: Install fetched node modules - if: steps.locate-cache.outputs.cache-hit != 'true' - run: npm ci - shell: bash diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8e940a3..50554b2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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' }} diff --git a/.github/workflows/codeql-analyze.yml b/.github/workflows/codeql-analyze.yml index 2be35ec..9952a8c 100644 --- a/.github/workflows/codeql-analyze.yml +++ b/.github/workflows/codeql-analyze.yml @@ -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 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e3d6f49..fcb19f5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index adda67c..b04832c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4e00e02..16d867b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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'