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
123 changes: 51 additions & 72 deletions .github/workflows/publish-to-npm.yaml
Original file line number Diff line number Diff line change
@@ -1,92 +1,71 @@
name: Check & Release
name: Publish to NPM

on:
# Push to master will deploy a beta version
push:
branches:
- master
# A release via GitHub releases will deploy a latest version
release:
types: [ published ]
workflow_call:
inputs:
ref:
description: Git ref to publish (branch, tag, or commit SHA)
required: true
type: string
dist-tag:
description: NPM dist-tag (latest or next)
required: false
type: string
default: 'latest'
workflow_dispatch:
inputs:
ref:
description: Git ref to publish (branch, tag, or commit SHA)
required: true
type: string
dist-tag:
description: NPM dist-tag (latest or next)
required: false
type: string
default: 'latest'

concurrency:
group: publish-to-npm
cancel-in-progress: false

permissions:
contents: write
id-token: write
contents: write

jobs:
build_and_test:
name: Build & Test
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [18, 20, 22]

steps:
- uses: actions/checkout@v4

- name: Setup node ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'

- name: Install Dependencies
run: npm install

- name: Run Tests
run: npm test
env:
APIFY_PROXY_PASSWORD: ${{ secrets.APIFY_TEST_USER_PROXY_PASSWORD }}

lint:
name: Lint
publish_to_npm:
name: Publish to NPM (${{ inputs.dist-tag }})
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v6
with:
node-version: 24
registry-url: 'https://registry.npmjs.org'
ref: ${{ inputs.ref }}
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
fetch-depth: 0

- run: npm install

- run: npm run lint

deploy:
name: Publish to NPM
needs: [build_and_test, lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup node
- name: Use Node.js 24
uses: actions/setup-node@v6
with:
node-version: 24
registry-url: 'https://registry.npmjs.org'

- name: Set Release Tag
run: echo "RELEASE_TAG=$(if [ ${{ github.event_name }} = release ]; then echo latest; else echo beta; fi)" >> $GITHUB_ENV

- name: Bump pre-release version
if: env.RELEASE_TAG == 'beta'
run: node ./.github/scripts/before-beta-release.cjs

- name: Install Dependencies
run: npm install

- name: Publish to NPM
run: npm publish --tag ${{ env.RELEASE_TAG }} --access public

- name: Tag Version
if: env.RELEASE_TAG == 'beta'
run: |
git_tag=v`node -p "require('./package.json').version"`
git tag $git_tag
git push origin $git_tag
- name: Publish to NPM (@latest)
if: inputs.dist-tag == 'latest'
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 5
retry_wait_seconds: 30
command: npm publish --tag latest --access public

- name: Publish to NPM (@next)
if: inputs.dist-tag == 'next'
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 5
retry_wait_seconds: 30
command: npm publish --tag next --access public
94 changes: 94 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Release @latest

on:
workflow_dispatch:
inputs:
version:
description: The version to bump (if you choose custom, please include it under custom version)
required: true
default: 'patch'
type: choice
options:
- 'patch'
- 'minor'
- 'major'
- 'custom'
custom_version:
description: The custom version to bump to (only for "custom" type)
required: false
type: string
default: ''

jobs:
build_and_test:
name: Build & Test
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [18, 20, 22]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}

- name: Install Dependencies
run: npm install

- name: Run Tests
run: npm test
env:
APIFY_PROXY_PASSWORD: ${{ secrets.APIFY_TEST_USER_PROXY_PASSWORD }}

release:
name: "Bump got-scraping: ${{ inputs.version }} version (${{ inputs.custom_version || 'n/a' }} custom version)"
needs: build_and_test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
fetch-depth: 0

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

- name: Install Dependencies
run: npm install

- name: Configure git
run: |
git config user.name "Apify Release Bot"
git config user.email "noreply@apify.com"

- name: Bump version to custom version
if: ${{ github.event.inputs.version == 'custom' && github.event.inputs.custom_version != '' }}
run: npm version ${{ github.event.inputs.custom_version }}

- name: Bump version to ${{ github.event.inputs.version }} version
if: ${{ github.event.inputs.version != 'custom' }}
run: npm version ${{ github.event.inputs.version }}

- name: Push version commit and tag
run: git push --follow-tags

- name: Get release SHA
id: release
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

- name: Publish packages
uses: apify/workflows/execute-workflow@main
with:
workflow: publish-to-npm.yaml
inputs: >
{
"ref": "${{ steps.release.outputs.sha }}",
"dist-tag": "latest"
}
Loading