Skip to content

Commit b4d2620

Browse files
authored
chore(ci): Clean up workflows, switch to publishing through OIDC (apify#627)
* chore(ci): Clean up workflows, switch to publishing through OIDC * Don't run tests on newer Node.js versions just yet
1 parent c585e59 commit b4d2620

File tree

2 files changed

+63
-160
lines changed

2 files changed

+63
-160
lines changed

.github/workflows/check.yaml

Lines changed: 29 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,38 @@
33
name: Check
44

55
on:
6-
pull_request:
6+
pull_request:
7+
workflow_call:
78

89
jobs:
9-
# NPM install is done in a separate job and cached to speed up the following jobs.
10-
build_and_test:
11-
name: Build & Test
12-
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
13-
runs-on: ${{ matrix.os }}
10+
lint_and_test:
11+
name: Lint & Test
12+
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
13+
runs-on: ubuntu-22.04
1414

15-
strategy:
16-
matrix:
17-
os: [ubuntu-22.04] # add windows-latest later
18-
node-version: [14, 16, 18]
15+
strategy:
16+
matrix:
17+
node-version: [14, 16, 18]
1918

20-
steps:
21-
-
22-
uses: actions/checkout@v2
23-
-
24-
name: Use Node.js ${{ matrix.node-version }}
25-
uses: actions/setup-node@v1
26-
with:
27-
node-version: ${{ matrix.node-version }}
28-
-
29-
name: Cache Node Modules
30-
if: ${{ matrix.node-version == 18 }}
31-
uses: actions/cache@v4
32-
with:
33-
path: |
34-
node_modules
35-
build
36-
key: cache-${{ github.run_id }}-v18
37-
-
38-
name: Install Dependencies
39-
run: npm install
40-
-
41-
name: Add localhost-test to Linux hosts file
42-
if: ${{ matrix.os == 'ubuntu-22.04' }}
43-
run: sudo echo "127.0.0.1 localhost-test" | sudo tee -a /etc/hosts
44-
# -
45-
# name: Add localhost-test to Windows hosts file
46-
# if: ${{ matrix.os == 'windows-latest' }}
47-
# run: echo "`n127.0.0.1 localhost-test">>C:\Windows\System32\drivers\etc\hosts
48-
-
49-
name: Run Tests
50-
run: npm test
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v6
5122

52-
lint:
53-
name: Lint
54-
needs: [build_and_test]
55-
runs-on: ubuntu-22.04
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v6
25+
with:
26+
node-version: ${{ matrix.node-version }}
5627

57-
steps:
58-
-
59-
uses: actions/checkout@v2
60-
-
61-
name: Use Node.js 18
62-
uses: actions/setup-node@v1
63-
with:
64-
node-version: 18
65-
-
66-
name: Load Cache
67-
uses: actions/cache@v4
68-
with:
69-
path: |
70-
node_modules
71-
build
72-
key: cache-${{ github.run_id }}-v18
73-
-
74-
run: npm run lint
28+
- name: Install Dependencies
29+
run: npm install
30+
31+
# Lint only on the latest Node.js version to save time.
32+
- name: Lint code
33+
if: ${{ matrix.node-version == 18 }}
34+
run: npm run lint
35+
36+
- name: Add localhost-test to Linux hosts file
37+
run: sudo echo "127.0.0.1 localhost-test" | sudo tee -a /etc/hosts
38+
39+
- name: Run Tests
40+
run: npm test

.github/workflows/release.yaml

Lines changed: 34 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -7,114 +7,51 @@ on:
77
- master
88
# A release via GitHub releases will deploy a latest version
99
release:
10-
types: [ published ]
10+
types: [published]
11+
12+
# Necessary permissions for publishing to NPM with OIDC
13+
permissions:
14+
contents: write
15+
id-token: write
1116

1217
jobs:
13-
# NPM install is done in a separate job and cached to speed up the following jobs.
14-
build_and_test:
15-
name: Build & Test
16-
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
17-
runs-on: ${{ matrix.os }}
18+
lint_and_test:
19+
name: Lint and test
20+
uses: ./.github/workflows/check.yaml
1821

19-
strategy:
20-
matrix:
21-
os: [ubuntu-22.04] # add windows-latest later
22-
node-version: [14, 16, 18]
22+
deploy:
23+
name: Publish to NPM
24+
needs: [lint_and_test]
25+
runs-on: ubuntu-22.04
2326

2427
steps:
25-
-
26-
uses: actions/checkout@v2
27-
-
28-
name: Use Node.js ${{ matrix.node-version }}
29-
uses: actions/setup-node@v1
30-
with:
31-
node-version: ${{ matrix.node-version }}
32-
-
33-
name: Cache Node Modules
34-
if: ${{ matrix.node-version == 18 }}
35-
uses: actions/cache@v4
28+
- name: Checkout repository
29+
uses: actions/checkout@v6
30+
31+
- name: Use Node.js 24
32+
uses: actions/setup-node@v6
3633
with:
37-
path: |
38-
node_modules
39-
build
40-
key: cache-${{ github.run_id }}-v18
41-
-
42-
name: Install Dependencies
34+
node-version: 24
35+
36+
- name: Install dependencies
4337
run: npm install
44-
- name: Add localhost-test to Linux hosts file
45-
if: ${{ matrix.os == 'ubuntu-22.04' }}
46-
run: sudo echo "127.0.0.1 localhost-test" | sudo tee -a /etc/hosts
47-
# -
48-
# name: Add localhost-test to Windows hosts file
49-
# if: ${{ matrix.os == 'windows-latest' }}
50-
# run: echo "`n127.0.0.1 localhost-test">>C:\Windows\System32\drivers\etc\hosts
51-
-
52-
name: Run Tests
53-
run: npm test
5438

55-
lint:
56-
name: Lint
57-
needs: [build_and_test]
58-
runs-on: ubuntu-22.04
39+
# Determine if this is a beta or latest release
40+
- name: Get release tag
41+
id: get_release_tag
42+
run: echo "release_tag=$(if [ ${{ github.event_name }} = release ]; then echo latest; else echo beta; fi)" >> $GITHUB_OUTPUT
5943

60-
steps:
61-
-
62-
uses: actions/checkout@v2
63-
-
64-
name: Use Node.js 18
65-
uses: actions/setup-node@v1
66-
with:
67-
node-version: 18
68-
-
69-
name: Load Cache
70-
uses: actions/cache@v4
71-
with:
72-
path: |
73-
node_modules
74-
build
75-
key: cache-${{ github.run_id }}-v18
76-
-
77-
run: npm run lint
44+
# Check version consistency and increment pre-release version number for beta only.
45+
- name: Bump pre-release version
46+
if: steps.get_release_tag.outputs.release_tag == 'beta'
47+
run: node ./.github/scripts/before-beta-release.js
7848

49+
- name: Publish to NPM
50+
run: npm publish --tag ${{ steps.get_release_tag.outputs.release_tag }}
7951

80-
# The deploy job is long but there are only 2 important parts. NPM publish
81-
# and triggering of docker image builds in the apify-actor-docker repo.
82-
deploy:
83-
name: Publish to NPM
84-
needs: [lint]
85-
runs-on: ubuntu-22.04
86-
steps:
87-
-
88-
uses: actions/checkout@v2
89-
-
90-
uses: actions/setup-node@v1
91-
with:
92-
node-version: 18
93-
registry-url: https://registry.npmjs.org/
94-
-
95-
name: Load Cache
96-
uses: actions/cache@v4
97-
with:
98-
path: |
99-
node_modules
100-
build
101-
key: cache-${{ github.run_id }}-v18
102-
-
103-
# Determine if this is a beta or latest release
104-
name: Set Release Tag
105-
run: echo "RELEASE_TAG=$(if [ ${{ github.event_name }} = release ]; then echo latest; else echo beta; fi)" >> $GITHUB_ENV
106-
-
107-
# Check version consistency and increment pre-release version number for beta only.
108-
name: Bump pre-release version
109-
if: env.RELEASE_TAG == 'beta'
110-
run: node ./.github/scripts/before-beta-release.js
111-
-
112-
name: Publish to NPM
113-
run: NODE_AUTH_TOKEN=${{secrets.NPM_TOKEN}} npm publish --tag ${{ env.RELEASE_TAG }} --access public
114-
-
115-
# Latest version is tagged by the release process so we only tag beta here.
116-
name: Tag Version
117-
if: env.RELEASE_TAG == 'beta'
52+
# Latest version is tagged by the release process so we only tag beta here.
53+
- name: Tag version
54+
if: steps.get_release_tag.outputs.release_tag == 'beta'
11855
run: |
11956
git_tag=v`node -p "require('./package.json').version"`
12057
git tag $git_tag

0 commit comments

Comments
 (0)