Skip to content

Commit 64b767b

Browse files
committed
[INFRA] Improve GitHub workflow and remove duplications
Introduce a local action to manage the npm cache and dependencies installation. All workflows now use it to ensure that the setup is done in same way everywhere. The surge preview won't generate teardown errors when the domain doesn't exist. This occurred when closing PR created by Dependabot.
1 parent 7917bf0 commit 64b767b

File tree

4 files changed

+26
-32
lines changed

4 files changed

+26
-32
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: 'Build Setup'
2+
description: 'Setup node and install dependencies'
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Setup node
8+
uses: actions/setup-node@v3
9+
with:
10+
node-version-file: '.nvmrc'
11+
- name: Install dependencies
12+
uses: bahmutov/npm-install@v1
13+
with:
14+
install-command: npm ci --ignore-scripts --prefer-offline --audit false --legacy-peer-deps

.github/workflows/build-pr.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@ jobs:
1616
runs-on: ubuntu-20.04
1717
steps:
1818
- uses: actions/checkout@v3
19-
- name: Setup node
20-
uses: actions/setup-node@v3
21-
with:
22-
node-version-file: '.nvmrc'
23-
cache: 'npm'
24-
- name: Install dependencies
25-
run: npm ci --legacy-peer-deps
19+
- name: Build Setup
20+
uses: ./.github/actions/build-setup
2621
- name: Lint check
2722
run: npm run lint-check
2823
- name: Check types

.github/workflows/deploy.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,8 @@ jobs:
2222
runs-on: ubuntu-20.04
2323
steps:
2424
- uses: actions/checkout@v3
25-
- name: Setup node
26-
uses: actions/setup-node@v3
27-
with:
28-
node-version-file: '.nvmrc'
29-
cache: 'npm'
30-
- name: Install dependencies
31-
run: npm ci --legacy-peer-deps
25+
- name: Build Setup
26+
uses: ./.github/actions/build-setup
3227
- name: create .env.production file
3328
run: |
3429
touch .env.production

.github/workflows/generate-site-preview.yml

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,25 @@ permissions:
1818
pull-requests: write
1919

2020
jobs:
21-
# inspired from https://github.com/process-analytics/github-actions-playground/pull/23
22-
check_secrets:
23-
runs-on: ubuntu-20.04
24-
outputs:
25-
is_SURGE_TOKEN_set: ${{ steps.secret_availability.outputs.is_SURGE_TOKEN_set }}
26-
steps:
27-
- name: Compute secrets availability
28-
id: secret_availability
29-
env:
30-
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
31-
run: |
32-
echo "is_SURGE_TOKEN_set: ${{ env.SURGE_TOKEN != '' }}"
33-
echo "::set-output name=is_SURGE_TOKEN_set::${{ env.SURGE_TOKEN != '' }}"
34-
3521
site_preview:
36-
needs: [check_secrets]
37-
if: needs.check_secrets.outputs.is_SURGE_TOKEN_set == 'true'
3822
runs-on: ubuntu-20.04
3923
steps:
24+
- uses: bonitasoft/actions/packages/[email protected]
25+
id: surge-preview-tools
26+
with:
27+
surge-token: ${{ secrets.SURGE_TOKEN }}
4028
- uses: actions/checkout@v3
4129
if: github.event.action != 'closed'
30+
- name: Build Setup
31+
if: github.event.action != 'closed'
32+
uses: ./.github/actions/build-setup
4233
- name: create .env.production file
4334
if: github.event.action != 'closed'
4435
run: |
4536
touch .env.production
4637
echo GATSBY_GA_MEASUREMENT_ID =${{ secrets.TEST_GA_MEASUREMENT_ID }} >> .env.production
4738
- name: Publish Site preview
48-
id: publish_site_preview
39+
if: steps.surge-preview-tools.outputs.can-run-surge-command == 'true'
4940
uses: afc163/surge-preview@v1
5041
with:
5142
surge_token: ${{ secrets.SURGE_TOKEN }}
@@ -54,5 +45,4 @@ jobs:
5445
failOnError: true
5546
teardown: 'true'
5647
build: |
57-
npm ci --legacy-peer-deps
5848
npm run build

0 commit comments

Comments
 (0)