Skip to content

Lock file maintenance #13606

Lock file maintenance

Lock file maintenance #13606

name: Tests and Deployments
on:
push:
pull_request:
schedule:
- cron: "0 8 * * *"
workflow_dispatch:
permissions:
# Required for NPM Trusted Publishing OIDC
# https://docs.npmjs.com/trusted-publishers#step-2-configure-your-cicd-workflow
id-token: write
jobs:
changes:
runs-on: ubuntu-latest
outputs:
musl-script: ${{ steps.filter.outputs.musl-script }}
steps:
- uses: actions/checkout@v7
- uses: dorny/paths-filter@v4.0.3
id: filter
with:
filters: |
musl-script:
- 'packages/apex-ast-serializer/tools/build-musl-toolchain.sh'
functional-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node:
- "26"
- "25"
- "24"
- "22"
java:
- "25"
- "21"
- "17"
include:
- node: "22"
java: "17"
ENABLE_CODE_COVERAGE: true
ENABLE_INTEGRATION_TESTS: true
env:
ENABLE_CODE_COVERAGE: ${{ matrix.ENABLE_CODE_COVERAGE }}
RUN_INTEGRATION_TESTS: ${{ matrix.ENABLE_INTEGRATION_TESTS && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags')) }}
name: Run tests on NodeJS ${{ matrix.node }} and Java ${{ matrix.java }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup pnpm
uses: pnpm/action-setup@v6.0.10
- name: Setup Node.js
uses: actions/setup-node@v7.0.0
with:
node-version: ${{ matrix.node }}
cache: pnpm
- uses: actions/setup-java@v6.0.0
with:
distribution: temurin
java-version: ${{ matrix.java }}
cache: gradle
# Starting with Node 17, DNS is resolved by order that the resolver
# returns it. In Github Actions environment, there is a loopback IP
# for ::1 to localhost, which means our tests try to connect to the ipv6
# interface, which the Java program does not listen on.
- name: Remove ipv6 loopback
run: sudo sed -Ei '/(^::1)/d' /etc/hosts
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Test Apex AST Serializer
run: pnpm nx run apex-ast-serializer:test
# Codecov upload needs CODECOV_TOKEN. It's absent on contributor forks,
# so resolve once: fail on the canonical repo, skip (with a warning) on a
# fork. Both upload steps below gate on the resolved availability.
- name: Resolve Codecov token
id: codecov_secret
if: matrix.ENABLE_CODE_COVERAGE
uses: ./.github/actions/resolve-secret
with:
name: CODECOV_TOKEN
value: ${{ secrets.CODECOV_TOKEN }}
- name: Upload Apex AST Serializer code coverage
if: matrix.ENABLE_CODE_COVERAGE && steps.codecov_secret.outputs.available == 'true'
uses: codecov/codecov-action@v7
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
flags: apex-ast-serializer
directory: packages/apex-ast-serializer
- name: Run Apex parsing server
run: pnpm nx run prettier-plugin-apex:start-server &
- name: Wait for Apex parsing server to be up
run: pnpm nx run prettier-plugin-apex:wait-server
- name: Run functional tests
run: AST_COMPARE=true pnpm nx run prettier-plugin-apex:test:parser --configuration built-in
- name: Upload Prettier Plugin Apex code coverage
if: matrix.ENABLE_CODE_COVERAGE && steps.codecov_secret.outputs.available == 'true'
uses: codecov/codecov-action@v7
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
flags: prettier-plugin-apex
directory: packages/prettier-plugin-apex
- name: Install integration test suite dependencies
if: env.RUN_INTEGRATION_TESTS == 'true'
run: sudo apt-get install -y -qq parallel
# This step is needed because integration tests rely on the
# existence of the compiled JS, as they are run using Node
# instead of tsx
- name: Build the project
if: env.RUN_INTEGRATION_TESTS == 'true'
run: pnpm nx run prettier-plugin-apex:build:dev
- name: Run integration tests
if: env.RUN_INTEGRATION_TESTS == 'true'
run: ./packages/prettier-plugin-apex/tests_integration/format/run-integration-tests.sh
package-tests:
name: Test latest Prettier Apex package
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
- macos-15-intel
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
- name: Setup pnpm
uses: pnpm/action-setup@v6.0.10
- name: Setup Node.js
uses: actions/setup-node@v7.0.0
with:
node-version: "24"
cache: pnpm
- uses: actions/setup-java@v6.0.0
with:
distribution: temurin
java-version: "17"
cache: gradle
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run package tests
run: pnpm nx run prettier-plugin-apex:test:package
build-native-executables:
name: Build Native Executables
needs: changes
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags') || needs.changes.outputs.musl-script == 'true'
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- macos-15-intel
- windows-latest
include:
- os: windows-latest
ASSET_NAME: apex-ast-serializer.exe
OUTPUT_NAME: apex-ast-serializer-win32-x64.exe
ARTIFACT_NAME: apex-ast-serializer-win32-x64.exe
- os: ubuntu-latest
ASSET_NAME: apex-ast-serializer
OUTPUT_NAME: apex-ast-serializer-linux-x64
ARTIFACT_NAME: apex-ast-serializer-linux-x64
# macOS 14 and above are ARM64 by default, see this link for more info:
# https://github.com/actions/runner-images?tab=readme-ov-file#available-images
- os: macos-latest
ASSET_NAME: apex-ast-serializer
OUTPUT_NAME: apex-ast-serializer-darwin-arm64
ARTIFACT_NAME: apex-ast-serializer-darwin-arm64
- os: macos-15-intel
ASSET_NAME: apex-ast-serializer
OUTPUT_NAME: apex-ast-serializer-darwin-x64
ARTIFACT_NAME: apex-ast-serializer-darwin-x64
env:
ASSET_NAME: ${{ matrix.ASSET_NAME }}
OUTPUT_NAME: ${{ matrix.OUTPUT_NAME }}
ARTIFACT_NAME: ${{ matrix.ARTIFACT_NAME }}
UPLOAD_ARTIFACTS: ${{ github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags') }}
OS: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ./packages/apex-ast-serializer
steps:
- uses: actions/checkout@v7
# NX_KEY enables Nx Cloud distributed caching. It's absent on contributor
# forks, so resolve it: fail on the canonical repo (a dropped key should
# be loud), and on a fork fall back to a cloud-less build below.
- name: Resolve Nx Cloud key
id: nx_secret
uses: ./.github/actions/resolve-secret
with:
name: NX_KEY
value: ${{ secrets.NX_KEY }}
- name: Setup pnpm
uses: pnpm/action-setup@v6.0.10
- name: Setup Node.js
uses: actions/setup-node@v7.0.0
with:
node-version: 24
cache: pnpm
- name: Set up JDK
uses: graalvm/setup-graalvm@v1.6.4
with:
java-version: "23"
distribution: "graalvm"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Restore NX cache
id: nx-cache-restore
uses: actions/cache/restore@v6.1.0
with:
path: |
.nx
key: ${{ matrix.os }}-nx-build-native-${{ hashFiles('packages/apex-ast-serializer/parser/**/*.java', 'packages/apex-ast-serializer/parser/**/*.properties', 'packages/apex-ast-serializer/parser/build.gradle', 'packages/apex-ast-serializer/libs/*.jar', 'packages/apex-ast-serializer/tools/build-native-binary.mjs') }}
- name: Build Linux musl toolchain
if: matrix.os == 'ubuntu-latest'
run: pnpm nx run apex-ast-serializer:build:musl
env:
NX_KEY: ${{ steps.nx_secret.outputs.available == 'true' && secrets.NX_KEY || '' }}
NX_NO_CLOUD: ${{ steps.nx_secret.outputs.available == 'true' && 'false' || 'true' }}
- name: Build native executable
run: pnpm nx run apex-ast-serializer:build:native
env:
# Needed for Windows; to resolve issue with temp folder during native image build, due to relativization
# problem when different drives are used, such as in GHA runners.
# https://github.com/graalvm/native-build-tools/issues/754
GRADLE_OPTS: -Djava.io.tmpdir=${{ runner.temp }}
# With the key present, use Nx Cloud. Without it (fork), disable cloud
# so nx doesn't try to decode a missing/empty key and fail.
NX_KEY: ${{ steps.nx_secret.outputs.available == 'true' && secrets.NX_KEY || '' }}
NX_NO_CLOUD: ${{ steps.nx_secret.outputs.available == 'true' && 'false' || 'true' }}
- name: Sanity check native executable
shell: bash
run: |
./parser/build/native/nativeCompile/${{ env.ASSET_NAME }} -l ../prettier-plugin-apex/tests/loop/LoopClass.cls > "$RUNNER_TEMP/sanity-check.json"
node -e "const fs=require('fs'); JSON.parse(fs.readFileSync(process.argv[1],'utf8')); console.log('Sanity check passed');" "$RUNNER_TEMP/sanity-check.json"
- name: Save NX Cache
uses: actions/cache/save@v6.1.0
with:
path: |
.nx
key: ${{ steps.nx-cache-restore.outputs.cache-primary-key }}
- name: Rename executable
run: mv parser/build/native/nativeCompile/${{ env.ASSET_NAME }} parser/build/native/nativeCompile/${{ env.OUTPUT_NAME }}
- name: Upload artifact
uses: actions/upload-artifact@v7.0.1
with:
name: ${{ env.OUTPUT_NAME }}
path: packages/apex-ast-serializer/parser/build/native/nativeCompile/${{ env.OUTPUT_NAME }}
release-to-registry:
runs-on: ubuntu-latest
name: Release to Registry
if: startsWith(github.ref, 'refs/tags')
permissions:
# Required for NPM Trusted Publishing OIDC
id-token: write
# Required for softprops/action-gh-release to create the GitHub Release
contents: write
needs:
- functional-tests
- build-native-executables
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup pnpm
uses: pnpm/action-setup@v6.0.10
- name: Setup Node.js
uses: actions/setup-node@v7.0.0
with:
# Need at least Node 24 for OIDC Trusted Publishing support
node-version: 24
cache: pnpm
registry-url: https://registry.npmjs.org
- uses: actions/setup-java@v6.0.0
with:
distribution: temurin
java-version: 17
cache: gradle
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build the project
run: pnpm run build
- name: Download Artifacts
uses: actions/download-artifact@v8.0.1
with:
path: /tmp/artifacts
pattern: apex-ast-serializer-*
merge-multiple: true
- name: Copy artifacts to correct packages
run: pnpm run install:native:ci /tmp/artifacts
- name: Check if prerelease
id: check_prerelease
continue-on-error: true
run: pnpm tsx scripts/check-prerelease.zx.mts
- name: Deploy packages
if: steps.check_prerelease.outcome == 'success'
run: pnpm --filter "prettier-plugin-apex" --filter "@prettier-apex/*" publish --no-git-checks --access public
- name: Deploy pre-release packages
if: steps.check_prerelease.outcome != 'success'
run: pnpm --filter "prettier-plugin-apex" --filter "@prettier-apex/*" publish --tag next --no-git-checks --access public
- name: Create GitHub Release
if: steps.check_prerelease.outcome == 'success'
uses: softprops/action-gh-release@v3.0.2