Skip to content

Commit b996bd8

Browse files
committed
build: add github workflow for deploying
1 parent fbd8499 commit b996bd8

File tree

1 file changed

+258
-0
lines changed

1 file changed

+258
-0
lines changed

.github/workflows/build-envs.yml

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
name: 'Build & Test Environments'
2+
on:
3+
push:
4+
branches:
5+
- develop
6+
- master
7+
- release/**
8+
pull_request:
9+
workflow_dispatch:
10+
inputs:
11+
commit:
12+
description: If the commit you want to test isn't the head of a branch, provide its SHA here
13+
required: false
14+
schedule:
15+
# Run every day at midnight (without cache)
16+
- cron: '0 0 * * *'
17+
18+
# Cancel in progress workflows on pull_requests.
19+
# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
22+
cancel-in-progress: true
23+
24+
env:
25+
HEAD_COMMIT: ${{ github.event.inputs.commit || github.sha }}
26+
27+
CACHED_DEPENDENCY_PATHS: |
28+
${{ github.workspace }}/node_modules
29+
${{ github.workspace }}/packages/*/node_modules
30+
${{ github.workspace }}/dev-packages/*/node_modules
31+
~/.cache/ms-playwright/
32+
~/.cache/mongodb-binaries/
33+
34+
# DEPENDENCY_CACHE_KEY: can't be set here because we don't have access to yarn.lock
35+
36+
# packages/utils/cjs and packages/utils/esm: Symlinks to the folders inside of `build`, needed for tests
37+
CACHED_BUILD_PATHS: |
38+
${{ github.workspace }}/packages/*/build
39+
${{ github.workspace }}/packages/ember/*.d.ts
40+
${{ github.workspace }}/packages/gatsby/*.d.ts
41+
${{ github.workspace }}/packages/core/src/version.ts
42+
${{ github.workspace }}/packages/serverless
43+
${{ github.workspace }}/packages/utils/cjs
44+
${{ github.workspace }}/packages/utils/esm
45+
46+
BUILD_CACHE_KEY: ${{ github.event.inputs.commit || github.sha }}
47+
BUILD_CACHE_TARBALL_KEY: tarball-${{ github.event.inputs.commit || github.sha }}
48+
49+
# GH will use the first restore-key it finds that matches
50+
# So it will start by looking for one from the same branch, else take the newest one it can find elsewhere
51+
# We want to prefer the cache from the current develop branch, if we don't find any on the current branch
52+
NX_CACHE_RESTORE_KEYS: |
53+
nx-Linux-${{ github.ref }}-${{ github.event.inputs.commit || github.sha }}
54+
nx-Linux-${{ github.ref }}
55+
nx-Linux
56+
57+
jobs:
58+
job_get_metadata:
59+
name: Get Metadata
60+
runs-on: ubuntu-20.04
61+
permissions:
62+
pull-requests: read
63+
steps:
64+
- name: Check out current commit
65+
uses: actions/checkout@v4
66+
with:
67+
ref: ${{ env.HEAD_COMMIT }}
68+
# We need to check out not only the fake merge commit between the PR and the base branch which GH creates, but
69+
# also its parents, so that we can pull the commit message from the head commit of the PR
70+
fetch-depth: 2
71+
- name: Get metadata
72+
id: get_metadata
73+
# We need to try a number of different options for finding the head commit, because each kind of trigger event
74+
# stores it in a different location
75+
run: |
76+
COMMIT_SHA=$(git rev-parse --short ${{ github.event.pull_request.head.sha || github.event.head_commit.id || env.HEAD_COMMIT }})
77+
echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_ENV
78+
echo "COMMIT_MESSAGE=$(git log -n 1 --pretty=format:%s $COMMIT_SHA)" >> $GITHUB_ENV
79+
80+
- name: Determine changed packages
81+
uses: getsentry/[email protected]
82+
id: changed
83+
with:
84+
filters: |
85+
shared: &shared
86+
- '*.{js,ts,json,yml,lock}'
87+
- 'CHANGELOG.md'
88+
- '.github/**'
89+
- 'jest/**'
90+
- 'scripts/**'
91+
- 'packages/core/**'
92+
- 'packages/rollup-utils/**'
93+
- 'packages/tracing/**'
94+
- 'packages/tracing-internal/**'
95+
- 'packages/utils/**'
96+
- 'packages/types/**'
97+
- 'packages/integrations/**'
98+
cloudflare:
99+
- *shared
100+
- *browser
101+
- 'dev-packages/env-tests/cloudflare-astro/**'
102+
any_code:
103+
- '!**/*.md'
104+
105+
- name: Get PR labels
106+
id: pr-labels
107+
uses: mydea/pr-labels-action@update-core
108+
109+
outputs:
110+
commit_label: '${{ env.COMMIT_SHA }}: ${{ env.COMMIT_MESSAGE }}'
111+
changed_cloudflare: ${{ steps.changed.outputs.cloudflare }}
112+
changed_any_code: ${{ steps.changed.outputs.any_code }}
113+
# Note: These next three have to be checked as strings ('true'/'false')!
114+
is_develop: ${{ github.ref == 'refs/heads/develop' }}
115+
is_release: ${{ startsWith(github.ref, 'refs/heads/release/') }}
116+
# When merging into master, or from master
117+
is_gitflow_sync: ${{ github.head_ref == 'master' || github.ref == 'refs/heads/master' }}
118+
has_gitflow_label:
119+
${{ github.event_name == 'pull_request' && contains(steps.pr-labels.outputs.labels, ' Gitflow ') }}
120+
force_skip_cache:
121+
${{ github.event_name == 'schedule' || (github.event_name == 'pull_request' &&
122+
contains(steps.pr-labels.outputs.labels, ' ci-skip-cache ')) }}
123+
124+
job_install_deps:
125+
name: Install Dependencies
126+
needs: job_get_metadata
127+
runs-on: ubuntu-20.04
128+
timeout-minutes: 15
129+
if: |
130+
(needs.job_get_metadata.outputs.is_gitflow_sync == 'false' && needs.job_get_metadata.outputs.has_gitflow_label == 'false') &&
131+
(needs.job_get_metadata.outputs.changed_any_code == 'true' || github.event_name != 'pull_request')
132+
steps:
133+
- name: 'Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})'
134+
uses: actions/checkout@v4
135+
with:
136+
ref: ${{ env.HEAD_COMMIT }}
137+
- name: Set up Node
138+
uses: actions/setup-node@v4
139+
with:
140+
node-version-file: 'package.json'
141+
# we use a hash of yarn.lock as our cache key, because if it hasn't changed, our dependencies haven't changed,
142+
# so no need to reinstall them
143+
- name: Compute dependency cache key
144+
id: compute_lockfile_hash
145+
run: echo "hash=${{ hashFiles('yarn.lock', '**/package.json') }}" >> "$GITHUB_OUTPUT"
146+
147+
- name: Check dependency cache
148+
uses: actions/cache@v3
149+
id: cache_dependencies
150+
with:
151+
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
152+
key: ${{ steps.compute_lockfile_hash.outputs.hash }}
153+
154+
- name: Install dependencies
155+
if: steps.cache_dependencies.outputs.cache-hit != 'true'
156+
run: yarn install --ignore-engines --frozen-lockfile
157+
outputs:
158+
dependency_cache_key: ${{ steps.compute_lockfile_hash.outputs.hash }}
159+
160+
cloudflare:
161+
name: Build
162+
needs: [job_get_metadata, job_install_deps]
163+
runs-on: ubuntu-20.04
164+
timeout-minutes: 30
165+
steps:
166+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
167+
uses: actions/checkout@v4
168+
with:
169+
ref: ${{ env.HEAD_COMMIT }}
170+
- name: Set up Node
171+
uses: actions/setup-node@v4
172+
with:
173+
node-version-file: 'package.json'
174+
- name: Check dependency cache
175+
uses: actions/cache/restore@v3
176+
with:
177+
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
178+
key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
179+
fail-on-cache-miss: true
180+
181+
- name: Check build cache
182+
uses: actions/cache@v3
183+
id: cache_built_packages
184+
with:
185+
path: ${{ env.CACHED_BUILD_PATHS }}
186+
key: ${{ env.BUILD_CACHE_KEY }}
187+
188+
- name: NX cache
189+
uses: actions/cache@v3
190+
# Disable cache when:
191+
# - on release branches
192+
# - when PR has `ci-skip-cache` label or on nightly builds
193+
if: |
194+
needs.job_get_metadata.outputs.is_release == 'false' &&
195+
needs.job_get_metadata.outputs.force_skip_cache == 'false'
196+
with:
197+
path: .nxcache
198+
key: nx-Linux-${{ github.ref }}-${{ env.HEAD_COMMIT }}
199+
# On develop branch, we want to _store_ the cache (so it can be used by other branches), but never _restore_ from it
200+
restore-keys:
201+
${{needs.job_get_metadata.outputs.is_develop == 'false' && env.NX_CACHE_RESTORE_KEYS || 'nx-never-restore'}}
202+
203+
- name: Build package
204+
# Under normal circumstances, using the git SHA as a cache key, there shouldn't ever be a cache hit on the built
205+
# packages, and so `yarn build` should always run. This `if` check is therefore only there for testing CI issues
206+
# where the built packages are beside the point. In that case, you can change `BUILD_CACHE_KEY` (at the top of
207+
# this file) to a constant and skip rebuilding all of the packages each time CI runs.
208+
if: steps.cache_built_packages.outputs.cache-hit == ''
209+
working-directory: dev-packages/env-tests/cloudflare-astro
210+
run: yarn build
211+
212+
- name: Publish to Cloudflare Pages
213+
uses: cloudflare/pages-action@v1
214+
if: steps.cache_built_packages.outputs.cache-hit == ''
215+
with:
216+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
217+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
218+
projectName: ${{ secrets.CLOUDFLARE_PROJECT_NAME }}
219+
directory: YOUR_BUILD_OUTPUT_DIRECTORY
220+
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
221+
workingDirectory: dev-packages/env-tests/cloudflare-astro
222+
223+
outputs:
224+
# this needs to be passed on, because the `needs` context only looks at direct ancestors (so steps which depend on
225+
# `job_build` can't see `job_install_deps` and what it returned)
226+
dependency_cache_key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
227+
228+
job_artifacts:
229+
name: Upload Artifacts
230+
needs: [job_get_metadata, job_build]
231+
runs-on: ubuntu-20.04
232+
# Build artifacts are only needed for releasing workflow.
233+
if: needs.job_get_metadata.outputs.is_release == 'true'
234+
steps:
235+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
236+
uses: actions/checkout@v4
237+
with:
238+
ref: ${{ env.HEAD_COMMIT }}
239+
- name: Set up Node
240+
uses: actions/setup-node@v4
241+
with:
242+
node-version-file: 'package.json'
243+
- name: Restore caches
244+
uses: ./.github/actions/restore-cache
245+
env:
246+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
247+
- name: Pack
248+
run: yarn build:tarball
249+
- name: Archive artifacts
250+
uses: actions/[email protected]
251+
with:
252+
name: ${{ github.sha }}
253+
path: |
254+
${{ github.workspace }}/packages/browser/build/bundles/**
255+
${{ github.workspace }}/packages/integrations/build/bundles/**
256+
${{ github.workspace }}/packages/replay/build/bundles/**
257+
${{ github.workspace }}/packages/**/*.tgz
258+
${{ github.workspace }}/packages/serverless/build/aws/dist-serverless/*.zip

0 commit comments

Comments
 (0)