Skip to content

Merge pull request #652 from actions-rs-plus/renovate/node-20.x #4

Merge pull request #652 from actions-rs-plus/renovate/node-20.x

Merge pull request #652 from actions-rs-plus/renovate/node-20.x #4

Workflow file for this run

# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Build
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: write
checks: write
pull-requests: write
issues: write
packages: write
concurrency:
group: "${{ github.workflow }} @ ${{ github.ref_name }}"
cancel-in-progress: true
jobs:
changes:
name: Detect changes
runs-on: ubuntu-latest
outputs:
code: ${{ steps.filter.outputs.code }}
steps:
- name: Checkout
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
show-progress: false
submodules: true
- name: Check if we actually made changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
token: ${{ secrets.GITHUB_TOKEN }}
filters: .github/file-filters.yml
warm-up-cache:
name: Warm up the cache
runs-on: ubuntu-latest
needs:
- changes
if: ${{ needs.changes.outputs.code == 'true' }}
steps:
- name: Check out code
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
submodules: true
- name: Set up node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version-file: ".nvmrc"
cache: "npm"
cache-dependency-path: package-lock.json
registry-url: https://npm.pkg.github.com
- name: Ensure latest version of npm, older versions like v8 have broken caching
shell: bash
run: |
npm install --location=global npm@latest
- name: Download dependencies
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm ci
npm-build:
name: Build the code
runs-on: ubuntu-latest
needs:
- warm-up-cache
steps:
- name: Check out code
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
fetch-depth: 0
token: ${{ secrets.TOKEN_TO_TRIGGER_SUBSEQUENT_WORKFLOWS }}
show-progress: false
submodules: true
- name: Set up node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version-file: ".nvmrc"
cache: "npm"
cache-dependency-path: package-lock.json
- name: Download dependencies from cache
shell: bash
run: |
npm ci --offline
- name: Run build
shell: bash
run: |
npm run build
- name: Compare the expected and actual dist/ directories
id: diff
env:
# for gh-cli
GH_TOKEN: ${{ secrets.TOKEN_TO_TRIGGER_SUBSEQUENT_WORKFLOWS }}
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
PR_NUMBER="${{ github.event.pull_request.number }}"
BRANCH="lock-file-maintenance-${PR_NUMBER}"
echo "Detected uncommitted changes after build. Checking in changes on branch: ${BRANCH}"
git checkout -b ${BRANCH}
echo "Please see the artifacts of this build for the changes"
git diff > diff.txt
echo "Creating commit with changes"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
echo "Committing changes in dist/"
git add dist/
git commit --message "chore: changes caused by updating lock files. See #${PR_NUMBER}"
# Remove GitHub's merging the tip of lock-file-maintenance branch into main's commit
# it's not needed as we require a branch to up-to-date with main
git rebase origin/main --autosquash
echo "Pushing branch"
git push --force --set-upstream origin HEAD
echo "Creating PR"
gh pr create --base main --head ${BRANCH} --title "chore(deps): rebuilding because of lock file maintenance" --fill
exit 1
fi
# If dist/ was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
path: |
dist/
diff.txt
npm-lint:
name: Lint the code
runs-on: ubuntu-latest
needs:
- warm-up-cache
steps:
- name: Check out code
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
show-progress: false
submodules: true
- name: Set up node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version-file: ".nvmrc"
cache: "npm"
cache-dependency-path: package-lock.json
- name: Download dependencies from cache
shell: bash
run: |
npm ci --offline
- name: Run lint
shell: bash
run: |
npm run lint -- --format=json --output-file reports/lint-report.json
continue-on-error: true
- name: Annotate Code Linting Results
uses: ataylorme/eslint-annotate-action@a1bf7cb320a18aa53cb848a267ce9b7417221526 # 1.2.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
report-json: reports/lint-report.json
npm-test:
name: Test the code
runs-on: ubuntu-latest
needs:
- warm-up-cache
steps:
- name: Check out code
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
show-progress: false
submodules: true
fetch-depth: 0
- name: Set up node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version-file: ".nvmrc"
cache: "npm"
cache-dependency-path: package-lock.json
- name: Download dependencies from cache
shell: bash
run: |
npm ci --offline
- name: Run tests
shell: bash
id: tests
env:
JEST_JUNIT_OUTPUT_DIR: reports/
JEST_JUNIT_OUTPUT_NAME: unit-tests-report.xml
run: |
npm run test:ci -- --coverage --testLocationInResults --reporters=default --reporters=jest-junit
continue-on-error: true
- name: Upload unit-test results
uses: enricomi/publish-unit-test-result-action@30eadd5010312f995f0d3b3cff7fe2984f69409e # v2.16.1
with:
check_name: Unit-test results
files: reports/unit-tests-report.xml
- name: Upload to Coveralls
uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # v2.2.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage/lcov.info
- name: Fail if tests failed
shell: bash
if: steps.tests.outcome != 'success'
run: |
echo "Tests failed"
exit 1
npm-dependencies:
name: Validate dependencies
runs-on: ubuntu-latest
needs:
- warm-up-cache
steps:
- name: Check out code
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
show-progress: false
- name: Set up node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version-file: ".nvmrc"
cache: "npm"
cache-dependency-path: package-lock.json
- name: Download dependencies from cache
shell: bash
run: |
npm ci --offline
- name: Check dependencies
shell: bash
run: |
npm run deps:ci
all-done:
name: All done
# this is the job that should be marked as required on GitHub. It's the only one that'll reliably trigger
# when any upstream fails: success
# when all upstream skips: pass
# when all upstream success: success
# combination of upstream skip and success: success
runs-on: ubuntu-latest
needs:
- npm-build
- npm-dependencies
- npm-lint
- npm-test
if: ${{ always() }}
steps:
- name: Fail!
shell: bash
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: |
echo "One / more upstream failed or was cancelled. Failing job..."
exit 1
- name: Success!
shell: bash
run: |
echo "Great success!"