Skip to content

build

build #6636

Workflow file for this run

# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".
name: build
on:
merge_group: {}
pull_request: {}
workflow_dispatch: {}
push:
branches:
- main
- maintenance/*
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
self-mutation-needed: ${{ steps.self-mutation.outputs.needed }}
env:
CI: "true"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
cache: yarn
- name: Cache build outputs
if: github.event_name == 'pull_request'
uses: actions/cache@v3
with:
key: build-outputs-${{ hashFiles('tsconfig.json', 'build-tools/**/*.ts', 'src/**/*.ts', 'package.json', 'yarn.lock') }}
path: |-
tsconfig.tsbuildinfo
lib/**/*
restore-keys: build-outputs-
- name: Install dependencies
run: yarn install --check-files
- name: compile
run: npx projen && npx projen pre-compile && npx projen compile && npx projen post-compile
- name: test
run: npx projen test
- name: Find mutations
id: self-mutation
run: |-
git add .
git diff --staged --patch --exit-code > .repo.patch || echo "needed=true" >> $GITHUB_OUTPUT
- name: Upload patch
if: steps.self-mutation.outputs.needed
uses: actions/upload-artifact@v4.3.6
with:
name: .repo.patch
path: .repo.patch
overwrite: true
- name: Fail if self-mutation is needed
if: steps.self-mutation.outputs.needed
run: |-
echo "::error::Files were changed during build (see build log). If this was triggered from a fork, you will need to update your branch."
cat .repo.patch
exit 1
- name: Upload artifact
uses: actions/upload-artifact@v4.3.6
with:
name: build-output
path: |-
${{ github.workspace }}
!${{ github.workspace }}/node_modules
!${{ github.workspace }}/fixtures/node_modules
overwrite: true
self-mutation:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
env:
CI: "true"
if: always() && (github.event_name == 'pull_request') && needs.build.outputs.self-mutation-needed && (github.event.pull_request.head.repo.full_name == github.repository)
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.PROJEN_GITHUB_TOKEN }}
- name: Download patch
uses: actions/download-artifact@v4
with:
name: .repo.patch
path: ${{ runner.temp }}
- name: Apply patch
run: '[ -s ${{ runner.temp }}/.repo.patch ] && git apply ${{ runner.temp }}/.repo.patch || echo "Empty patch. Skipping."'
- name: Set git identity
run: |-
git config user.name "github-actions"
git config user.email "github-actions@github.com"
- name: Push changes
run: |-
git add .
git commit -s -m "chore: self-mutation"
git push origin HEAD:${{ github.event.pull_request.head.ref }}
matrix-test:
name: test (node ${{ matrix.node-version }})
needs: build
runs-on: ubuntu-latest
permissions: {}
env:
CI: "true"
if: success()
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: build-output
path: ${{ github.workspace }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Re-run post-compile
run: npx projen post-compile
- name: Test
run: npx projen test
- name: Assert clean working directory
run: git diff --staged --exit-code
strategy:
fail-fast: false
matrix:
node-version:
- 18.x
- 20.x
- 22.x
matrix-clear:
name: Unit Tests
needs: matrix-test
runs-on: ubuntu-latest
permissions: {}
env:
CI: "true"
if: always()
steps:
- name: Build result
run: echo ${{needs.matrix-test.result}}
- name: Set status based on matrix build
if: ${{ needs.matrix-test.result != 'success' }}
run: exit 1
package:
name: package
needs: build
runs-on: ubuntu-latest
permissions: {}
env:
CI: "true"
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: build-output
path: ${{ github.workspace }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Package
run: npx projen package
- name: Upload artifact
uses: actions/upload-artifact@v4.3.6
with:
name: release-package
path: ${{ github.workspace }}/dist
overwrite: true