Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/actions/checkout-restore-dependencies/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Checkout and restore dependencies
description: Checkout and restore dependencies
inputs:
working-directory:
type: string
description: Working directory
required: false
default: .
additional-working-directory:
type: string
description: Additional working directory
required: false

runs:
using: "composite"
steps:
- id: checkout
uses: actions/checkout@v5

- name: Load cached dependencies
id: restore-dependency-cache
uses: actions/cache/restore@v5
with:
fail-on-cache-miss: true
path: ${{ inputs.working-directory }}/node_modules
key: modules-npm-${{ inputs.working-directory }}-${{ hashFiles(format('{0}/package-lock.json', inputs.working-directory)) }}

- name: Load additional cached dependencies
if: inputs.additional-working-directory != ''
id: restore-additional-dependency-cache
uses: actions/cache/restore@v5
with:
fail-on-cache-miss: true
path: ${{ inputs.additional-working-directory }}/node_modules
key: modules-npm-${{ inputs.additional-working-directory }}-${{ hashFiles(format('{0}/package-lock.json', inputs.additional-working-directory)) }}
46 changes: 46 additions & 0 deletions .github/workflows/cache-dependencies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Cache Dependencies

on:
workflow_call:
inputs:
working-directory:
type: string
default: .
required: false
additional-working-directory:
type: string
required: false

jobs:
cache-dependencies:
name: Cache Dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- name: Cache dependencies npm
id: check-dependencies-cache
uses: actions/cache@v5
with:
path: ${{ inputs.working-directory }}/node_modules
key: modules-npm-${{ inputs.working-directory }}-${{ hashFiles(format('{0}/package-lock.json', inputs.working-directory)) }}

- name: Cache additional dependencies npm
if: inputs.additional-working-directory != ''
id: check-additional-dependencies-cache
uses: actions/cache@v5
with:
path: ${{ inputs.additional-working-directory }}/node_modules
key: modules-npm-${{ inputs.additional-working-directory }}-${{ hashFiles(format('{0}/package-lock.json', inputs.additional-working-directory)) }}

- name: install npm dependencies
if: steps.check-dependencies-cache.outputs.cache-hit != 'true'
run: |
cd ${{ inputs.working-directory }}
npm ci

- name: install additional npm dependencies
if: steps.check-additional-dependencies-cache.outputs.cache-hit != 'true'
run: |
cd ${{ inputs.additional-working-directory }}
npm ci
8 changes: 4 additions & 4 deletions .github/workflows/platform-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ jobs:
working-directory: ${{ inputs.working-directory }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0
fetch-depth: 0

- uses: oNaiPs/secrets-to-env-action@b64e0192bc4bd2ec0682dee8696470d4866577fa
with:
secrets: ${{ toJSON(secrets) }}
secrets: ${{ toJSON(secrets) }}

- name: Install dependencies
run: npm install
Expand Down Expand Up @@ -70,4 +70,4 @@ jobs:
if: always()
with:
name: vitest-results
path: ./test-output.json
path: ./test-output.json
132 changes: 68 additions & 64 deletions .github/workflows/pr-build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
type: string
default: .
required: false
additional-working-directory:
type: string
required: false
skip-platform-tests:
type: boolean
default: false
Expand All @@ -17,24 +20,29 @@ concurrency:
cancel-in-progress: true

jobs:
cache-dependencies:
uses: ./.github/workflows/cache-dependencies.yaml
with:
working-directory: ${{ inputs.working-directory }}
additional-working-directory: ${{ inputs.additional-working-directory }}

checkTestFolder:
if: ${{ !inputs.skip-platform-tests }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.working-directory }}

steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Check for test folder
id: check
run: |
if [ ! -d "test/platform" ]; then
echo "No platform test folder found. Failing the workflow."
exit 1
fi
if [ ! -d "test/platform" ]; then
echo "No platform test folder found. Failing the workflow."
exit 1
fi

platformTest:
if: ${{ !inputs.skip-platform-tests }}
Expand All @@ -45,24 +53,24 @@ jobs:
working-directory: ${{ inputs.working-directory }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0
fetch-depth: 0

- uses: oNaiPs/secrets-to-env-action@b64e0192bc4bd2ec0682dee8696470d4866577fa
with:
secrets: ${{ toJSON(secrets) }}
secrets: ${{ toJSON(secrets) }}

- name: Pick last validated commit from cache
id: base_commit
uses: actions/cache@v4
uses: actions/cache@v5
with:
# We have to call it base commit for the library but it makes more sense as "last validated commit"
# Using run_id ensures the key is always unique so the cache always saves at end-of-job (no "cache hit, not saving" issue)
path: ./base_commit.txt
key: base_commit-${{ github.run_id }}
# This is needed to force overriding the cache with new entry at the end
restore-keys: base_commit-
# We have to call it base commit for the library but it makes more sense as "last validated commit"
# Using run_id ensures the key is always unique so the cache always saves at end-of-job (no "cache hit, not saving" issue)
path: ./base_commit.txt
key: base_commit-${{ github.run_id }}
# This is needed to force overriding the cache with new entry at the end
restore-keys: base_commit-

- name: Install dependencies
run: npm install
Expand Down Expand Up @@ -109,56 +117,52 @@ jobs:
unitTest:
# TODO: only run on changes to code
runs-on: ubuntu-latest
needs: cache-dependencies
defaults:
run:
working-directory: ${{ inputs.working-directory }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20
cache: 'npm'
cache-dependency-path: ${{ inputs.working-directory }} # https://github.com/actions/setup-node/issues/706
- name: Install Dependencies
run: npm ci

- name: TypeScript
# Some repos require custom build checks, so we check if the `build-check` script exists and run it if
# it does. Otherwise default to the standard `npx tsc --noEmit` check
run: |
HAS_CUSTOM_BUILD_CHECK=$(npx -y json -f package.json scripts.build-check)
if [ -z "$HAS_CUSTOM_BUILD_CHECK" ]; then
npx tsc --noEmit;
else
npm run build-check;
fi

- name: Lint
run: npm run lint

- name: Test
run: npm test

- name: Prettier Check
run: |
if [ -d "node_modules/prettier" ]; then
npx prettier --check .;
else
echo "Prettier is not installed. Skipping Prettier check.";
fi

- name: Unused Exports Check
run: |
if [ -d "node_modules/knip" ]; then
echo "Knip is installed. Running knip to check for unused exports.";
npx knip --include exports,types;
elif [ -d "node_modules/ts-unused-exports" ]; then
echo "Knip is not installed, but ts-unused-exports is. Running ts-unused-exports to check for unused exports.";
npx ts-unused-exports ./tsconfig.json;
else
echo "knip nor ts-unused-exports are installed. Skipping unused exports check.";
fi
- name: Setup repository and dependencies
# Referenced globally, local reference failed when looking for the action in the consumer repo
# it was being looked for within the repo, not as a relative path to this job when invoked
uses: apify-projects/github-actions-source/.github/actions/checkout-restore-dependencies@dependency-cache
with:
working-directory: ${{ inputs.working-directory }}

- name: TypeScript
# Some repos require custom build checks, so we check if the `build-check` script exists and run it if
# it does. Otherwise default to the standard `npx tsc --noEmit` check
run: |
HAS_CUSTOM_BUILD_CHECK=$(npx -y json -f package.json scripts.build-check)
if [ -z "$HAS_CUSTOM_BUILD_CHECK" ]; then
npx tsc --noEmit;
else
npm run build-check;
fi

- name: Lint
run: npm run lint

- name: Test
run: npm test

- name: Prettier Check
run: |
if [ -d "node_modules/prettier" ]; then
npx prettier --check .;
else
echo "Prettier is not installed. Skipping Prettier check.";
fi

- name: Unused Exports Check
run: |
if [ -d "node_modules/knip" ]; then
echo "Knip is installed. Running knip to check for unused exports.";
npx knip --include exports,types;
elif [ -d "node_modules/ts-unused-exports" ]; then
echo "Knip is not installed, but ts-unused-exports is. Running ts-unused-exports to check for unused exports.";
npx ts-unused-exports ./tsconfig.json;
else
echo "knip nor ts-unused-exports are installed. Skipping unused exports check.";
fi
12 changes: 6 additions & 6 deletions .github/workflows/push-build-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ on:

jobs:
pushBuildLatest:
name: 'Build latest: ${{github.repository}} ${{github.event.head_commit.message}}'
name: "Build latest: ${{github.repository}} ${{github.event.head_commit.message}}"
if: |
!contains(github.event.head_commit.message, '[skip ci]') &&
!contains(github.event.head_commit.message, '[skip platform-test]')
!contains(github.event.head_commit.message, '[skip ci]') &&
!contains(github.event.head_commit.message, '[skip platform-test]')

runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.working-directory }}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
fetch-depth: 0
fetch-depth: 0
# A simple node script that converts secrets to env vars
# Use specific commit SHA to prevent someone stealing that repo
- uses: oNaiPs/secrets-to-env-action@b64e0192bc4bd2ec0682dee8696470d4866577fa
with:
secrets: ${{ toJSON(secrets) }}
secrets: ${{ toJSON(secrets) }}

- name: Install dependencies
run: npm install
Expand Down