Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create s3 QA deploy #58

Merged
merged 22 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
59a3b48
Initial commit
sneakyjoeru Mar 7, 2024
54d568e
chore: switch file/name
sneakyjoeru Mar 15, 2024
8145058
feat: specify PR number for S3 directory
sneakyjoeru Mar 19, 2024
53d1fc5
chore: cleanup
sneakyjoeru Mar 20, 2024
1d83c02
chore: rename
sneakyjoeru Mar 20, 2024
d9c7d35
formatting
sneakyjoeru Mar 20, 2024
bf3f693
chore: source maps delete
sneakyjoeru Mar 20, 2024
ef1bb14
test: delete push requirement
sneakyjoeru Apr 25, 2024
4e0552d
test: checkout fetch depth 0
sneakyjoeru Apr 25, 2024
8299c2c
test: deploy all the time
sneakyjoeru Apr 25, 2024
d48e17c
fix: remove upload public folder
poignant-wit Apr 25, 2024
1d5c195
feat(build-and-deploy-to-s3-qa): add with_nx option
poignant-wit Apr 26, 2024
078c84c
feat(build-and-deploy-to-cloudfront): add with_nx option
poignant-wit Apr 26, 2024
6138a43
feat(build-and-deploy-to-cloudfront): add with_nx option
poignant-wit Apr 26, 2024
b4c046a
fix: set nx main-branch-name
poignant-wit Apr 26, 2024
f7c06e1
fix(build-and-deploy-to-s3-qa) : do not track master branch on pr close
poignant-wit Apr 30, 2024
aefc1f7
fix(build-and-deploy-to-s3-qa) : do not build on close/merge PR
poignant-wit Apr 30, 2024
17a363b
fix: directly pass github repo name and pr number
sneakyjoeru Jul 10, 2024
eda9c14
feat: allow runs on master
sneakyjoeru Jul 10, 2024
39a2aa0
feat: set default name for context values
sneakyjoeru Jul 10, 2024
e59bb3b
fix: inputs reference
sneakyjoeru Jul 10, 2024
cc66894
Merge branch 'master' into Create-S3-deploy
CarpathianUA Oct 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions .github/workflows/build-and-deploy-to-cloudfront.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ on:
type: boolean
default: true
required: false
concurrency_name:
type: string
default: "build-n-deploy"
# ======
# NX monorepo tools
# ======
with_nx:
type: boolean
default: false
required: false

secrets:
sentry_auth_token:
required: false
Expand All @@ -100,6 +104,8 @@ jobs:
- name: Checkout source code
uses: actions/checkout@v4
timeout-minutes: 1
with:
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v4
Expand Down Expand Up @@ -132,6 +138,14 @@ jobs:
build-cache-${{ (inputs.package_manager == 'yarn') && hashFiles('yarn.lock') || hashFiles('package-lock.json') }}
build-cache-

- uses: nrwl/nx-set-shas@v3
with:
main-branch-name: "master"
if: inputs.with_nx

- run: git branch --track master origin/master
if: ${{ github.event_name == 'pull_request' && inputs.with_nx }}

- name: Build
run: ${{ inputs.build_command }}
timeout-minutes: 15
Expand Down
155 changes: 155 additions & 0 deletions .github/workflows/build-and-deploy-to-s3-qa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
---
name: Build and deploy to S3 QA


on:
workflow_call:
inputs:
# =====
# Setup
# =====
instance_type:
type: string
default: xlarge
required: false
node_version:
type: string
# If set to '' version will be extracted from .nvmrc file
default: "16"
required: false
node_options:
type: string
required: false
package_manager:
type: string
default: yarn
required: false
# =====
# Github Context variables
# =====
repo_name:
type: string
required: false
default: ${{ github.event.repository.name }}
pr_number:
type: string
required: false
default: ${{ github.event.pull_request.number }}
# =====
# Build
# =====
build_command:
type: string
default: yarn build
required: false
build_cache_path:
type: string
required: false
build_path:
type: string
default: ./dist
required: false
# ======
# Deploy
# ======
s3_bucket_name:
type: string
required: true
# ======
# NX monorepo tools
# ======
with_nx:
type: boolean
default: false
required: false

concurrency:
group: ${{ inputs.repo_name }}-build-n-deploy-s3-${{ inputs.pr_number }}
cancel-in-progress: true

jobs:
print-url:
name: Print the url of QA build
runs-on: ["self-hosted", "xsmall", "prod"]
if: github.event.action == 'opened'
timeout-minutes: 1
steps:
- name: Leave comment with domain name
uses: mshick/add-pr-comment@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: |
QA Build will be available here: [https://${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }}.qa.restream.io](https://${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }}.qa.restream.io)
build:
name: Build and deploy to S3
runs-on: ["self-hosted", "${{ inputs.instance_type }}", "prod"]
if: (github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.merged != true)
steps:
- name: Show context
env:
# To make debugging easier in case of issues
GITHUB_CONTEXT_JSON: ${{ toJson(github) }}
INPUTS_JSON: ${{ toJson(inputs) }}
run: |
echo Github context: "$GITHUB_CONTEXT_JSON"
echo Inputs: "$INPUTS_JSON"

- name: Checkout source code
uses: actions/checkout@v4
with:
fetch-depth: 0
timeout-minutes: 1

- name: Setup Node
uses: actions/setup-node@v4
timeout-minutes: 5
with:
node-version: ${{ inputs.node_version }}
node-version-file: .nvmrc
cache: ${{ inputs.package_manager }}

- name: Install dependencies
run: ${{ (inputs.package_manager == 'yarn') && 'npm install -g yarn && yarn install --frozen-lockfile' || 'npm ci' }}
timeout-minutes: 10

- name: Cache build
if: inputs.build_cache_path
timeout-minutes: 5
uses: actions/cache@v4
with:
path: ${{ inputs.build_cache_path }}
key: build-cache-${{ (inputs.package_manager == 'yarn') && hashFiles('yarn.lock') || hashFiles('package-lock.json') }}-${{ github.ref }}
restore-keys: |
build-cache-${{ (inputs.package_manager == 'yarn') && hashFiles('yarn.lock') || hashFiles('package-lock.json') }}
build-cache-

- uses: nrwl/nx-set-shas@v3
with:
main-branch-name: "master"
if: inputs.with_nx

- run: git branch --track master origin/master
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.merged != true && inputs.with_nx }}

- name: Build
run: ${{ inputs.build_command }}
timeout-minutes: 15
env:
COMMIT_HASH: ${{ github.sha }}
NODE_OPTIONS: ${{ inputs.node_options }}

- name: Deploy to S3
timeout-minutes: 15
run: |
cd ${{ inputs.build_path }}
aws s3 cp . "s3://${{ inputs.s3_bucket_name }}/${{ github.event.pull_request.number }}" --recursive --no-progress --exclude "*.js.map"

cleanup:
name: Cleanup
runs-on: ["self-hosted", "${{ inputs.instance_type }}", "prod"]
if: (github.event_name == 'pull_request' && github.event.action == 'closed') || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
steps:
- name: Delete S3 directory on PR close
run: |
aws s3 rm s3://${{ inputs.s3_bucket_name }}/${{ github.event.pull_request.number }} --recursive