Skip to content

Commit e9b35f5

Browse files
ci: Set up an automated release process (#691)
- closes #496 --------- Co-authored-by: Vlad Frangu <[email protected]>
1 parent 433c154 commit e9b35f5

File tree

3 files changed

+340
-126
lines changed

3 files changed

+340
-126
lines changed

.github/workflows/check.yaml

Lines changed: 2 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This workflow runs for every pull request to lint and test the proposed changes.
22

3-
name: Check & Release
3+
name: Check
44

55
on:
66
# Push to master will deploy a beta version
@@ -25,11 +25,6 @@ jobs:
2525
node-version: [18, 20, 22]
2626

2727
steps:
28-
- name: Cancel Workflow Action
29-
uses: styfle/[email protected]
30-
with:
31-
access_token: ${{ github.token }}
32-
3328
- uses: actions/checkout@v4
3429

3530
- name: Use Node.js ${{ matrix.node-version }}
@@ -128,6 +123,7 @@ jobs:
128123
cd website
129124
yarn
130125
yarn build
126+
131127
lint:
132128
name: Lint
133129
runs-on: ubuntu-latest
@@ -158,123 +154,3 @@ jobs:
158154

159155
- name: Run format checks
160156
run: yarn format
161-
162-
# The deploy job is long but there are only 2 important parts. NPM publish
163-
# and triggering of docker image builds in the apify-actor-docker repo.
164-
deploy:
165-
name: Publish to NPM
166-
if: github.repository_owner == 'apify' && (github.ref == 'refs/heads/master' || github.event_name == 'release') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, 'docs:')
167-
needs: [build_and_test, test_python_support, lint]
168-
runs-on: ubuntu-latest
169-
steps:
170-
- uses: actions/checkout@v4
171-
with:
172-
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
173-
fetch-depth: 0
174-
175-
- name: Use Node.js 20
176-
uses: actions/setup-node@v4
177-
with:
178-
node-version: 20
179-
registry-url: https://registry.npmjs.org
180-
181-
- name: Enable corepack
182-
run: |
183-
corepack enable
184-
corepack prepare yarn@stable --activate
185-
186-
- name: Activate cache for Node.js 20
187-
uses: actions/setup-node@v4
188-
with:
189-
cache: yarn
190-
191-
- name: Set git identity
192-
run: |
193-
git config --global user.name 'Apify Service Account'
194-
git config --global user.email '[email protected]'
195-
196-
- name: Install Dependencies
197-
run: yarn
198-
199-
# Determine if this is a beta or latest release
200-
- name: Set Release Tag
201-
run: echo "RELEASE_TAG=$(if [ ${{ github.event_name }} = release ]; then echo latest; else echo beta; fi)" >> $GITHUB_ENV
202-
203-
# Check version consistency and increment pre-release version number for beta only.
204-
- name: Bump pre-release version
205-
if: env.RELEASE_TAG == 'beta'
206-
run: yarn tsx ./.github/scripts/before-beta-release.ts
207-
208-
- name: Publish to NPM
209-
run: |
210-
yarn config set npmAuthToken ${NODE_AUTH_TOKEN}
211-
yarn npm publish --tag ${{ env.RELEASE_TAG }} --access public
212-
env:
213-
NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}
214-
215-
# Latest version is tagged by the release process so we only tag beta here.
216-
- name: Tag Version
217-
if: env.RELEASE_TAG == 'beta'
218-
run: |
219-
git_tag=v`node -p "require('./package.json').version"`
220-
git tag $git_tag
221-
git push origin $git_tag
222-
223-
- name: Update readme
224-
if: env.RELEASE_TAG == 'latest'
225-
run: |
226-
git update-index --assume-unchanged .yarnrc.yml
227-
git add .
228-
git diff-index --quiet HEAD || git commit -m "[skip ci] update README with latest command reference"
229-
git push origin HEAD:master
230-
231-
update_homebrew_formula:
232-
name: Update Homebrew Formula
233-
needs: [deploy]
234-
runs-on: ubuntu-latest
235-
if: github.repository_owner == 'apify' && github.event_name == 'release' && github.event.action == 'published'
236-
steps:
237-
- name: Checkout repository
238-
uses: actions/checkout@v4
239-
240-
- name: Set git identity
241-
run: |
242-
git config --global user.name 'Apify Service Account'
243-
git config --global user.email '[email protected]'
244-
245-
- name: Set up Homebrew
246-
uses: Homebrew/actions/setup-homebrew@master
247-
248-
# It can happen that the updated package version is not available right after the `npm publish` command finishes
249-
# Try waiting 3 minutes until the updated package version is available
250-
- name: Wait for updated package to be available on NPM
251-
run: |
252-
PACKAGE_VERSION=`node -p "require('./package.json').version"`
253-
PACKAGE_DEFINITION_URL="https://registry.npmjs.org/apify-cli/${PACKAGE_VERSION}"
254-
255-
for _i in {1..30}; do
256-
curl -sf "${PACKAGE_DEFINITION_URL}" &> /dev/null && exit 0;
257-
echo "Package 'apify-cli' version '${PACKAGE_VERSION}' is not available yet, will retry in 10 seconds."
258-
sleep 10;
259-
done
260-
curl -sf "${PACKAGE_DEFINITION_URL}" &> /dev/null || exit 1;
261-
262-
- name: Update Homebrew formula in apify/homebrew-tap repo
263-
run: |
264-
PACKAGE_VERSION=`node -p "require('./package.json').version"`
265-
gh workflow run update_formula.yaml --repo apify/homebrew-tap --field package=apify-cli --field version=$PACKAGE_VERSION
266-
env:
267-
GH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
268-
269-
- name: Send PR with formula update to homebrew/homebrew-core repo
270-
run: |
271-
PACKAGE_VERSION=`node -p "require('./package.json').version"`
272-
brew tap --force homebrew/core
273-
brew bump-formula-pr apify-cli \
274-
--version ${PACKAGE_VERSION} \
275-
--no-browse \
276-
--message "Automatic update of the \`apify-cli\` formula.
277-
278-
CC @B4nan @vladfrangu"
279-
env:
280-
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}

.github/workflows/pre_release.yaml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Create a pre-release
2+
3+
on:
4+
# Push to master will deploy a beta version
5+
push:
6+
branches:
7+
- master
8+
tags-ignore:
9+
- "**" # Ignore all tags to prevent duplicate builds when tags are pushed.
10+
11+
concurrency:
12+
group: release
13+
cancel-in-progress: false
14+
15+
jobs:
16+
release_metadata:
17+
if: "!startsWith(github.event.head_commit.message, 'docs') && !startsWith(github.event.head_commit.message, 'ci') && startsWith(github.repository, 'apify/')"
18+
name: Prepare release metadata
19+
runs-on: ubuntu-latest
20+
outputs:
21+
version_number: ${{ steps.release_metadata.outputs.version_number }}
22+
changelog: ${{ steps.release_metadata.outputs.changelog }}
23+
steps:
24+
- uses: apify/workflows/git-cliff-release@main
25+
name: Prepare release metadata
26+
id: release_metadata
27+
with:
28+
release_type: prerelease
29+
existing_changelog_path: CHANGELOG.md
30+
31+
wait_for_checks:
32+
name: Wait for code checks to pass
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: lewagon/[email protected]
36+
with:
37+
ref: ${{ github.ref }}
38+
repo-token: ${{ secrets.GITHUB_TOKEN }}
39+
check-regexp: (Build & Test .*|Test Python template support|Lint|Docs build)
40+
wait-interval: 5
41+
42+
update_changelog:
43+
needs: [release_metadata, wait_for_checks]
44+
name: Update changelog
45+
runs-on: ubuntu-latest
46+
outputs:
47+
changelog_commitish: ${{ steps.commit.outputs.commit_long_sha || github.sha }}
48+
steps:
49+
- name: Checkout repository
50+
uses: actions/checkout@v4
51+
with:
52+
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
53+
54+
- name: Use Node.js 22
55+
uses: actions/setup-node@v4
56+
with:
57+
node-version: 22
58+
registry-url: https://registry.npmjs.org
59+
60+
- name: Enable corepack
61+
run: |
62+
corepack enable
63+
corepack prepare yarn@stable --activate
64+
git update-index --assume-unchanged .yarnrc.yml
65+
66+
- name: Activate cache for Node.js 22
67+
uses: actions/setup-node@v4
68+
with:
69+
cache: yarn
70+
71+
- name: Update README
72+
run: |
73+
yarn npm pack
74+
75+
- name: Update package version in package.json
76+
run: yarn npm version --no-git-tag-version --allow-same-version ${{ needs.release_metadata.outputs.version_number }}
77+
78+
- name: Update CHANGELOG.md
79+
uses: DamianReeves/write-file-action@master
80+
with:
81+
path: CHANGELOG.md
82+
write-mode: overwrite
83+
contents: ${{ needs.release_metadata.outputs.changelog }}
84+
85+
- name: Commit changes
86+
id: commit
87+
uses: EndBug/add-and-commit@v9
88+
with:
89+
author_name: Apify Release Bot
90+
author_email: [email protected]
91+
message: "chore(release): Update changelog and package version [skip ci]"
92+
93+
publish_to_npm:
94+
name: Publish to NPM
95+
needs: [update_changelog]
96+
runs-on: ubuntu-latest
97+
steps:
98+
- uses: actions/checkout@v4
99+
with:
100+
ref: ${{ needs.update_changelog.changelog_commitish }}
101+
102+
- name: Use Node.js 22
103+
uses: actions/setup-node@v4
104+
with:
105+
node-version: 22
106+
registry-url: https://registry.npmjs.org
107+
108+
- name: Enable corepack
109+
run: |
110+
corepack enable
111+
corepack prepare yarn@stable --activate
112+
113+
- name: Activate cache for Node.js 22
114+
uses: actions/setup-node@v4
115+
with:
116+
cache: yarn
117+
118+
- name: Install dependencies
119+
run: yarn
120+
121+
# Check version consistency and increment pre-release version number for beta only.
122+
- name: Bump pre-release version
123+
run: yarn tsx ./.github/scripts/before-beta-release.ts
124+
125+
- name: Build module
126+
run: yarn build
127+
128+
- name: Publish to NPM
129+
run: |
130+
yarn config set npmAuthToken ${NODE_AUTH_TOKEN}
131+
yarn npm publish --tag beta --access public
132+
env:
133+
NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}

0 commit comments

Comments
 (0)