Skip to content

Commit 6c27c0f

Browse files
feat(ci/cd): configured ci/cd for github actions
1 parent 17d4080 commit 6c27c0f

File tree

8 files changed

+480
-0
lines changed

8 files changed

+480
-0
lines changed

.github/actions/build/action.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build package
2+
3+
inputs:
4+
vercel-token:
5+
description: 'Token to access the vercel'
6+
required: true
7+
pull-env-args:
8+
description: 'Arguments to pull env from vercel'
9+
required: true
10+
build-env-args:
11+
description: 'Arguments to build env'
12+
required: true
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- name: Install Vercel CLI
18+
shell: bash
19+
run: npm i --global vercel
20+
21+
- name: Get Env
22+
shell: bash
23+
run: vercel pull ${{ inputs.pull-env-args }} --token=${{ inputs.vercel-token }}
24+
25+
- name: Vercel build local
26+
shell: bash
27+
run: vercel build ${{ inputs.build-env-args }}
28+
29+
- name: Deploy Prebuilt to Vercel
30+
shell: bash
31+
run: vercel deploy --prebuilt ${{ inputs.build-env-args }} --token=${{ inputs.vercel-token }}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Build preview
2+
3+
inputs:
4+
vercel-token:
5+
description: 'Token to access the vercel'
6+
required: true
7+
github-token:
8+
description: 'Token to access the github'
9+
required: true
10+
vercel-org-id:
11+
description: 'Vercel org id'
12+
required: true
13+
vercel-project-id:
14+
description: 'Vercel project id to deploy'
15+
required: true
16+
vercel-project-name:
17+
description: 'Vercel project name to deploy'
18+
required: true
19+
20+
runs:
21+
using: "composite"
22+
steps:
23+
- name: Install Vercel CLI
24+
shell: bash
25+
run: npm i --global vercel
26+
27+
- name: Get Env
28+
shell: bash
29+
run: vercel pull --environment=preview --token=${{ inputs.vercel-token }}
30+
31+
- name: Vercel build local
32+
shell: bash
33+
run: vercel build
34+
35+
# - name: Deploy
36+
# uses: amondnet/vercel-action@v25
37+
# with:
38+
# vercel-token: ${{ inputs.vercel-token}} # Required
39+
# github-token: ${{ inputs.github-token }} #Optional
40+
# vercel-args: "--prebuilt"
41+
# vercel-org-id: ${{ inputs.vercel-org-id}} #Required
42+
# vercel-project-id: ${{ inputs.vercel-project-id }} #Required
43+
# vercel-project-name: ${{ inputs.vercel-project-name }}
44+
# vercel-version: 30.2.0
45+
46+
- name: Deploy Prebuilt to Vercel
47+
shell: bash
48+
run: vercel deploy --prebuilt --token=${{ inputs.vercel-token }}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Prepare environment
2+
3+
inputs:
4+
repo-token:
5+
description: 'Token to access the repo'
6+
required: true
7+
8+
runs:
9+
using: 'composite'
10+
steps:
11+
- uses: actions/setup-node@v3
12+
with:
13+
node-version: 20
14+
cache: 'npm'
15+
16+
- name: Install Packages
17+
shell: bash
18+
run: npm ci
19+
env:
20+
CI: true

.github/pull_request_template.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
**What does this PR do?**
2+
3+
- [x] My bugfix
4+
5+
**Related Ticket(s)**
6+
7+
- Notion Ticket
8+
9+
**Key Changes**
10+
11+
- How does the code change address the issue? Describe, at a high level, what was done to affect change.
12+
- What side effects does this change have? This is the most important question to answer, as it can point out problems where you are making too many changes in one commit or branch. One or two bullet points for related changes may be okay, but five or six are likely indicators of a commit that is doing too many things.
13+
14+
**How to test**
15+
16+
- Create a detailed description of what you need to do to set this PR up. ie: Does it need migrations? Do you need to install something?
17+
- Create a step by step list of what the engineer needs to do to test.
18+
19+
**Media (Loom or gif)**
20+
21+
- Insert media here (if applicable)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: 'Determine changed packages'
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
package_changed:
7+
description: 'Dry run of turbo to determine which packages have changed since the last release'
8+
value: ${{ jobs.dry-run.outputs.package_changed }}
9+
10+
jobs:
11+
dry-run:
12+
runs-on: ubuntu-latest
13+
env:
14+
# The turbo filter here varies depending on if we're using this workflow in a PR or on a push to a branch
15+
# For PRs, we want to use `github.event.pull_request.base.sha` to tell turbo to see which packages changed since that SHA
16+
# For a branch push/merges, the above sha isn't available, so instead, we reference `github.event.before` to determine the previous `HEAD` of the branch we just pushed onto
17+
# See SO answer for more info https://stackoverflow.com/a/61861763/2379922
18+
TURBO_REF_FILTER: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || 'HEAD^' }}
19+
outputs:
20+
# Defining a job output for used by the next jobs:
21+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idoutputs
22+
package_changed: ${{ steps.changeset.outputs.result }}
23+
24+
steps:
25+
- uses: actions/checkout@v2
26+
with:
27+
# see `fetch-depth` in README: https://github.com/actions/checkout#checkout-v3,
28+
# we set to `0` so the referenced commits are available for the command below
29+
fetch-depth: 0
30+
31+
- name: Changeset
32+
id: changeset
33+
shell: bash
34+
# 1. We need the 'output' of a turbo dry-run to get a json with all affected packages of these run.
35+
# 2. The multi line json string is wrapped in EOF delimeters to make the GHA happy: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
36+
# 3. We specify the .github/ folder as a dependency here. Just to be safe, if workflows changed, we use that to mean everything has changes pending... to force redeploys
37+
run: |
38+
echo 'result<<CHANGESET_DELIMITER' >> $GITHUB_OUTPUT
39+
echo "$(npx -y turbo build --dry-run=json --filter=...[$TURBO_REF_FILTER])" >> $GITHUB_OUTPUT
40+
echo 'CHANGESET_DELIMITER' >> $GITHUB_OUTPUT
41+
# - name: Echo info
42+
# shell: bash
43+
# run: |
44+
# echo "Changeset: ${{ steps.changeset.outputs.result }}"

.github/workflows/deploy-dev.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Development Deployment
2+
permissions:
3+
actions: write
4+
contents: write
5+
packages: write
6+
checks: read
7+
pull-requests: write
8+
deployments: write
9+
10+
env:
11+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
12+
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
13+
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
14+
on:
15+
push:
16+
branches:
17+
- main
18+
jobs:
19+
pre_job:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
should_skip: ${{ steps.skip_check.outputs.should_skip }}
23+
steps:
24+
- id: skip_check
25+
uses: fkirc/skip-duplicate-actions@v5
26+
with:
27+
# All of these options are optional, so you can remove them if you are happy with the defaults
28+
concurrent_skipping: 'outdated_runs'
29+
# paths_ignore: '["**/README.md", ".github/**"]'
30+
cancel_others: 'true'
31+
32+
changed-packages:
33+
name: Determine which apps changed
34+
needs: [pre_job]
35+
if: needs.pre_job.outputs.should_skip != 'true'
36+
uses: ./.github/workflows/changed-packages.yaml
37+
Deploy-Development:
38+
runs-on: ubuntu-latest
39+
needs: [pre_job, changed-packages]
40+
if: needs.pre_job.outputs.should_skip != 'true'
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v3
44+
with:
45+
fetch-depth: 2
46+
47+
- name: Prepare Environment
48+
uses: ./.github/actions/setup-env
49+
timeout-minutes: 10
50+
with:
51+
repo-token: ${{ secrets.GITHUB_TOKEN }}
52+
53+
- name: Deploy API_HARMONIZATION Project Artifacts to Vercel
54+
if: contains(toJson(fromJson(needs.changed-packages.outputs.package_changed).packages), 'api-harmonization') && always()
55+
env:
56+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_API_HARMONIZATION_PROJECT_ID }}
57+
uses: ./.github/actions/build
58+
timeout-minutes: 10
59+
with:
60+
vercel-token: ${{ secrets.VERCEL_ACCESS_TOKEN }}
61+
pull-env-args: '--environment=preview'
62+
build-env-args: ''
63+
64+
- name: Deploy FRONTEND Project Artifacts to Vercel
65+
if: contains(toJson(fromJson(needs.changed-packages.outputs.package_changed).packages), 'frontend') && always()
66+
env:
67+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_FRONTEND_PROJECT_ID }}
68+
uses: ./.github/actions/build
69+
timeout-minutes: 10
70+
with:
71+
vercel-token: ${{ secrets.VERCEL_ACCESS_TOKEN }}
72+
pull-env-args: '--environment=preview'
73+
build-env-args: ''

.github/workflows/preview.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Preview Deployment
2+
permissions:
3+
actions: write
4+
contents: read
5+
checks: read
6+
pull-requests: write
7+
deployments: write
8+
9+
env:
10+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
11+
on:
12+
pull_request:
13+
types: [opened, synchronize]
14+
jobs:
15+
pre_job:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
should_skip: ${{ steps.skip_check.outputs.should_skip }}
19+
steps:
20+
- id: skip_check
21+
uses: fkirc/skip-duplicate-actions@v5
22+
with:
23+
# All of these options are optional, so you can remove them if you are happy with the defaults
24+
concurrent_skipping: 'outdated_runs'
25+
# paths_ignore: '["**/README.md", "**/ag-guideline.md", "**/docs/**", ".github/**"]'
26+
cancel_others: 'true'
27+
28+
changed-packages:
29+
needs: pre_job
30+
if: needs.pre_job.outputs.should_skip != 'true'
31+
name: Determine which apps changed
32+
uses: ./.github/workflows/changed-packages.yaml
33+
Deploy-Preview:
34+
runs-on: ubuntu-latest
35+
needs: [pre_job, changed-packages]
36+
if: needs.pre_job.outputs.should_skip != 'true'
37+
steps:
38+
- name: Checkout code
39+
uses: actions/checkout@v3
40+
with:
41+
fetch-depth: 2
42+
ref: ${{ needs.check-app.outputs.branch }}
43+
- name: Prepare Environment
44+
uses: ./.github/actions/setup-env
45+
timeout-minutes: 10
46+
with:
47+
repo-token: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: Deploy API_HARMONIZATION
50+
if: contains(toJson(fromJson(needs.changed-packages.outputs.package_changed).packages), 'api') && always()
51+
env:
52+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_API_HARMONIZATION_PROJECT_ID }}
53+
uses: ./.github/actions/preview
54+
timeout-minutes: 10
55+
with:
56+
vercel-token: ${{ secrets.VERCEL_ACCESS_TOKEN }} # Required
57+
github-token: ${{ secrets.GITHUB_TOKEN }} #Optional
58+
vercel-org-id: ${{ secrets.VERCEL_ORG_ID}} #Required
59+
vercel-project-id: ${{ secrets.VERCEL_API_HARMONIZATION_PROJECT_ID }} #Required
60+
vercel-project-name: 'api-harmonization'
61+
62+
- name: Deploy FRONTEND
63+
if: contains(toJson(fromJson(needs.changed-packages.outputs.package_changed).packages), 'frontend') && always()
64+
env:
65+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_FRONTEND_PROJECT_ID }}
66+
uses: ./.github/actions/preview
67+
timeout-minutes: 10
68+
with:
69+
vercel-token: ${{ secrets.VERCEL_ACCESS_TOKEN }} # Required
70+
github-token: ${{ secrets.GITHUB_TOKEN }} #Optional
71+
vercel-org-id: ${{ secrets.VERCEL_ORG_ID}} #Required
72+
vercel-project-id: ${{ secrets.VERCEL_FRONTEND_PROJECT_ID }} #Required
73+
vercel-project-name: 'frontend'

0 commit comments

Comments
 (0)