Skip to content

Commit 61a7cb6

Browse files
author
Roberto Santalla
authored
ci/pr-deploy: Combine build and upload jobs (#1183)
* ci/pr-deploy: remove `update-dependencies` job Both npm and node_modules cache will be generated by other PRs regardless of this job. * ci/pr-deploy: coalesce build and deploy jobs By doing this, we remove the need to upload the build output as a GH artifact as an intermediary step. * ci/pr-deploy: restore node_modules cache on build job
1 parent 5bc509d commit 61a7cb6

File tree

1 file changed

+20
-46
lines changed

1 file changed

+20
-46
lines changed

.github/workflows/pr-deploy.yml

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,8 @@ on:
1515
branches: main
1616

1717
jobs:
18-
update-dependencies:
19-
name: Update node module dependencies
20-
runs-on: ubuntu-latest
21-
steps:
22-
- name: Checkout project
23-
uses: actions/checkout@v2
24-
- name: Use Node.js 16.xs
25-
uses: actions/setup-node@v2
26-
with:
27-
node-version: '16.x'
28-
registry-url: 'https://registry.npmjs.org'
29-
cache: 'npm'
30-
- name: Restore cache
31-
uses: actions/cache@v2
32-
with:
33-
path: '**/node_modules'
34-
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
35-
- name: Install dependencies
36-
run: npm install
3718
lint:
3819
name: Lint code
39-
needs: [update-dependencies]
4020
runs-on: ubuntu-latest
4121
steps:
4222
- name: Checkout project
@@ -77,7 +57,7 @@ jobs:
7757
fail_on_error: true
7858
vale_flags: '--glob=**/{docs,translated-guides/en}/**/*.md'
7959
build:
80-
name: Build pull request
60+
name: Build and deploy pull request
8161
runs-on: ubuntu-latest
8262
needs: lint
8363
steps:
@@ -98,6 +78,12 @@ jobs:
9878
registry-url: 'https://registry.npmjs.org'
9979
cache: 'npm'
10080

81+
- name: Restore node_modules cache
82+
uses: actions/cache@v2
83+
with:
84+
path: '**/node_modules'
85+
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
86+
10187
- name: Install
10288
run: npm install
10389

@@ -117,47 +103,35 @@ jobs:
117103
- name: Build
118104
run: npm run build
119105

120-
- name: Upload artifact
121-
uses: actions/upload-artifact@v2
122-
with:
123-
name: k6-docs
124-
path: public/
125-
retention-days: 1
126-
127-
deploy:
128-
name: Deploy pull request
129-
runs-on: ubuntu-latest
130-
needs: [build]
131-
if: github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'
132-
env:
133-
AWS_ACCESS_KEY_ID: ${{ secrets.PR_CI_AWS_ACCESS_KEY }}
134-
AWS_SECRET_ACCESS_KEY: ${{ secrets.PR_CI_AWS_SECRET_KEY }}
135-
AWS_REGION: 'eu-west-1'
136-
137-
steps:
138-
- name: Download artifact
139-
uses: actions/download-artifact@v2
140-
with:
141-
name: k6-docs
142-
path: public/
143-
144106
- name: Sync to S3
107+
id: upload
108+
# Run only if PR does not come from a fork and it is not from dependabot.
109+
if: github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'
145110
uses: jakejarvis/[email protected]
146111
with:
147112
args: --delete
148113
env:
114+
AWS_ACCESS_KEY_ID: ${{ secrets.PR_CI_AWS_ACCESS_KEY }}
115+
AWS_SECRET_ACCESS_KEY: ${{ secrets.PR_CI_AWS_SECRET_KEY }}
116+
AWS_REGION: 'eu-west-1'
149117
AWS_S3_BUCKET: ${{ secrets.PR_CI_AWS_S3_BUCKET }}
150118
SOURCE_DIR: public/
151119
DEST_DIR: docs/${{ github.ref }}
152120

153121
- name: Invalidate Cloudfront
122+
# Run only if we did not skip the upload step
123+
if: steps.upload.outcome == 'success'
154124
uses: chetan/[email protected]
155125
env:
126+
AWS_ACCESS_KEY_ID: ${{ secrets.PR_CI_AWS_ACCESS_KEY }}
127+
AWS_SECRET_ACCESS_KEY: ${{ secrets.PR_CI_AWS_SECRET_KEY }}
128+
AWS_REGION: 'eu-west-1'
156129
DISTRIBUTION: ${{ secrets.PR_CI_CLOUDFRONT_DISTRIBUTION_ID }}
157130
PATHS: '/docs/*'
158131

159132
- name: Post published URL to PR
160-
if: github.event.action == 'opened'
133+
# Run only if we did not skip the upload step and it's the first run for this PR.
134+
if: steps.upload.outcome == 'success' && github.event.action == 'opened'
161135
uses: actions/[email protected]
162136
with:
163137
github-token: ${{secrets.GITHUB_TOKEN}}

0 commit comments

Comments
 (0)