Skip to content
Merged
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
36 changes: 36 additions & 0 deletions .github/scripts/before-beta-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable no-console */
import { execSync } from 'node:child_process';
import { readFileSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

const PKG_JSON_PATH = join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'package.json');

const pkgJson = JSON.parse(readFileSync(PKG_JSON_PATH, 'utf8'));

const PACKAGE_NAME = pkgJson.name;
const VERSION = pkgJson.version;

const nextVersion = addBetaSuffixToVersion(VERSION);
console.log(`before-deploy: Setting version to ${nextVersion}`);
pkgJson.version = nextVersion;

writeFileSync(PKG_JSON_PATH, `${JSON.stringify(pkgJson, null, 2)}\n`);

function addBetaSuffixToVersion(version) {
const versionString = execSync(`npm show ${PACKAGE_NAME} versions --json`, { encoding: 'utf8' });
const versions = JSON.parse(versionString);

if (versions.some((v) => v === version)) {
console.error(
`before-deploy: A release with version ${version} already exists. Please increment version accordingly.`,
);
process.exit(1);
}

const prereleaseNumbers = versions
.filter((v) => v.startsWith(version) && v.includes('-'))
.map((v) => Number(v.match(/\.(\d+)$/)[1]));
const lastPrereleaseNumber = Math.max(-1, ...prereleaseNumbers);
return `${version}-beta.${lastPrereleaseNumber + 1}`;
}
78 changes: 78 additions & 0 deletions .github/workflows/_check_code.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Code checks

on:
workflow_call:
workflow_dispatch:

permissions:
contents: read

jobs:
actions_lint_check:
name: Actions lint check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Run actionlint
uses: rhysd/actionlint@v1.7.11

spell_check:
name: Spell check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Check spelling with typos
uses: crate-ci/typos@v1

lint_check:
name: Lint check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: 'npm'
cache-dependency-path: 'package-lock.json'
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint

type_check:
name: Type check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: 'npm'
cache-dependency-path: 'package-lock.json'
- name: Install dependencies
run: npm ci
- name: Type check
run: npm run type-check

build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: 'npm'
cache-dependency-path: 'package-lock.json'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
35 changes: 35 additions & 0 deletions .github/workflows/_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Tests

on:
workflow_dispatch:
workflow_call:

permissions:
contents: read

jobs:
unit_tests:
name: Unit tests (Node.js ${{ matrix.node-version }})
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [18, 20, 22, 24]

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

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: 'package-lock.json'

- name: Install dependencies
run: npm ci

- name: Unit tests
run: npm test
86 changes: 86 additions & 0 deletions .github/workflows/_update_release_metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Update release metadata

on:
workflow_call:
inputs:
release_type:
description: Release type
type: string
default: auto
custom_version:
description: The custom version to bump to (only for "custom" type)
type: string
default: ''
outputs:
version_number:
description: The version number for the release
value: ${{ jobs.release_metadata.outputs.version_number }}
tag_name:
description: The tag name for the release
value: ${{ jobs.release_metadata.outputs.tag_name }}
changelog:
description: The full changelog content
value: ${{ jobs.release_metadata.outputs.changelog }}
release_notes:
description: The release notes for this version
value: ${{ jobs.release_metadata.outputs.release_notes }}
changelog_commitish:
description: The commit SHA after changelog update
value: ${{ jobs.update_changelog.outputs.changelog_commitish }}

permissions:
contents: write

jobs:
release_metadata:
name: Prepare release metadata
runs-on: ubuntu-latest
outputs:
version_number: ${{ steps.release_metadata.outputs.version_number }}
tag_name: ${{ steps.release_metadata.outputs.tag_name }}
changelog: ${{ steps.release_metadata.outputs.changelog }}
release_notes: ${{ steps.release_metadata.outputs.release_notes }}
steps:
- uses: apify/workflows/git-cliff-release@main
name: Prepare release metadata
id: release_metadata
with:
release_type: ${{ inputs.release_type }}
custom_version: ${{ inputs.custom_version }}
existing_changelog_path: CHANGELOG.md
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}

update_changelog:
needs: [release_metadata]
name: Update changelog
runs-on: ubuntu-latest
outputs:
changelog_commitish: ${{ steps.commit.outputs.commit_long_sha || github.sha }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}

- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: 24

- name: Update package version
run: npm version --no-git-tag-version --allow-same-version ${{ needs.release_metadata.outputs.version_number }}

- name: Update changelog
uses: DamianReeves/write-file-action@master
with:
path: CHANGELOG.md
write-mode: overwrite
contents: ${{ needs.release_metadata.outputs.changelog }}

- name: Commit changes
id: commit
uses: EndBug/add-and-commit@v9
with:
author_name: Apify Release Bot
author_email: noreply@apify.com
message: 'chore(release): Update changelog and package version [skip ci]'
51 changes: 51 additions & 0 deletions .github/workflows/manual_publish_to_npm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: NPM publish

on:
workflow_dispatch:
inputs:
ref:
description: Git ref to publish (branch, tag, or commit SHA)
required: true
type: string
tag:
description: NPM dist-tag
required: true
type: choice
default: latest
options:
- latest
- beta

permissions:
id-token: write
contents: read

jobs:
npm_publish:
name: NPM publish
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ inputs.ref }}
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: 24
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
cache-dependency-path: 'package-lock.json'
- name: Update npm
run: npm install -g npm@latest
- name: Install dependencies
run: npm ci
- name: Bump pre-release version
if: ${{ inputs.tag == 'beta' }}
run: node ./.github/scripts/before-beta-release.js
- name: Build
run: npm run build
- name: Publish
run: npm publish --provenance --tag ${{ inputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}
80 changes: 80 additions & 0 deletions .github/workflows/manual_release_stable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Stable release

on:
workflow_dispatch:
inputs:
release_type:
description: Release type
required: true
type: choice
default: auto
options:
- auto
- custom
- patch
- minor
- major
custom_version:
description: The custom version to bump to (only for "custom" type)
required: false
type: string
default: ''

concurrency:
group: release
cancel-in-progress: false

permissions:
contents: read

jobs:
code_checks:
name: Code checks
uses: ./.github/workflows/_check_code.yaml

tests:
name: Tests
uses: ./.github/workflows/_tests.yaml

release_metadata:
name: Update release metadata
needs: [code_checks, tests]
permissions:
contents: write
uses: ./.github/workflows/_update_release_metadata.yaml
secrets: inherit
with:
release_type: ${{ inputs.release_type }}
custom_version: ${{ inputs.custom_version }}

github_release:
name: GitHub release
needs: [release_metadata]
runs-on: ubuntu-latest
permissions:
contents: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.release_metadata.outputs.tag_name }}
name: ${{ needs.release_metadata.outputs.version_number }}
target_commitish: ${{ needs.release_metadata.outputs.changelog_commitish }}
body: ${{ needs.release_metadata.outputs.release_notes }}

npm_publish:
name: NPM publish
needs: [release_metadata]
runs-on: ubuntu-latest
steps:
- name: Execute publish workflow
uses: apify/workflows/execute-workflow@main
with:
workflow: manual_publish_to_npm.yaml
inputs: >
{
"ref": "${{ needs.release_metadata.outputs.changelog_commitish }}",
"tag": "latest"
}
Loading
Loading