Skip to content

Commit

Permalink
feat: split from builder monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
sampullman committed Feb 16, 2024
0 parents commit a14105b
Show file tree
Hide file tree
Showing 30 changed files with 5,094 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The dotenv files are picked up when running npx `nx serve builder-demo`.
# This has been the preferred way of running the frontend apps locally,
# because k8s introduces some delay for hot module reloading (HMR),
# which slows down development, and the extra pods eat up quite a few resources.

VITE_EXEC_ENV=dev

VITE_SITE_FORMAT_VERSION=0.1
54 changes: 54 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module.exports = {
env: {
node: true,
},
extends: ['plugin:vue/vue3-recommended', '@vue/typescript/recommended', 'prettier'],
plugins: ['import'],
parser: 'vue-eslint-parser',
parserOptions: { ecmaVersion: 2020 },
ignorePatterns: ['!**/*', 'node_modules/'],
rules: {
'no-console': 'off',
'no-debugger': process.env.NODE_ENV === 'prod' ? 'error' : 'off',
'padded-blocks': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
'no-multiple-empty-lines': ['error', { max: 1 }],
'keyword-spacing': ['error', { after: true }],
'max-len': ['error', { code: 110, ignorePattern: '^\\s*<path' }],
'no-param-reassign': [2, { props: false }],
'object-curly-newline': [
'error',
{
consistent: true,
multiline: true,
},
],
'no-extra-boolean-cast': 'error',
'import/extensions': [
'error',
'never',
{
vue: 'always',
json: 'always',
form: 'always',
png: 'always',
svg: 'always',
webm: 'always',
jpg: 'always',
mp3: 'always',
mp4: 'always',
},
],
'vue/attribute-hyphenation': ['error', 'never'],
'vue/singleline-html-element-content-newline': [
'error',
{
ignoreWhenNoAttributes: true,
ignoreWhenEmpty: true,
},
],
'vue/no-v-html': 'off',
'vue/v-on-event-hyphenation': 'off',
},
}
18 changes: 18 additions & 0 deletions .github/actions/env-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Environment Setup
description: 'Setup PNPM and Node'
runs:
using: 'composite'
steps:
- name: Setup PNPM
uses: pnpm/action-setup@v2.4.0
with:
version: 8.7.0
- name: Set up NodeJS v20
uses: actions/setup-node@v3
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
cache: 'pnpm'
- name: Install npm modules
shell: bash
run: pnpm install --ignore-scripts --frozen-lockfile
50 changes: 50 additions & 0 deletions .github/actions/repo-metadata/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Repo Metadata
description: 'Generate sha8 of latest commit and next release version'
inputs:
github_token:
description: 'secrets.GITHUB_TOKEN'
required: true
outputs:
sha8:
description: 'Latest commit sha8'
value: ${{ steps.slug.outputs.sha8 }}
repo_slug:
description: 'Latest commit sha8'
value: ${{ steps.repo_slug.outputs.result }}
next_version:
description: 'Next release version'
value: ${{ steps.preview_release.outputs.next_version }}
runs:
using: 'composite'
steps:
- name: Get last commit short SHA
shell: bash
id: slug
run: echo "sha8=$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT
- name: Sanitize repo owner slug
uses: actions/github-script@v6
id: repo_slug
with:
result-encoding: string
script: return `ghcr.io/${context.repo.owner.toLowerCase()}/${context.repo.repo.toLowerCase()}`
- name: Checkout branch
shell: bash
run: git checkout $GITHUB_HEAD_REF
- name: Set up NodeJS (LTS)
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
- name: Install dependencies
shell: bash
run: |
npm install -g semantic-release@23
npm install -g @semantic-release/changelog
- name: Preview semantic-release
shell: bash
id: preview_release
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
run: |
export NEXT_VERSION=$(unset GITHUB_ACTIONS && npx semantic-release --dry-run --no-ci --branches main | grep 'The next release version is' | sed -E 's/.* ([[:digit:].]+)$/\1/')
echo "$NEXT_VERSION"
echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
58 changes: 58 additions & 0 deletions .github/workflows/pr-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: PR Commit
on:
pull_request:
branches: [main]
env:
WORKSPACE_ROOT: .
CACHE_SUFFIX: d # cache busting

# Cancel redundant workflow runs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pre_job:
name: Run Workflow?
runs-on: ubuntu-22.04
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@master
with:
concurrent_skipping: 'never'
skip_after_successful_duplicate: 'true'
# Changes to paths must be synced with pr-merge*.yml
paths: '[".github/workflows/pr-commit.yml", "apps/**", "backend/**", "libs/**", "*"]'
paths_ignore: '["**/README.md", "skaffold*.yaml"]'

check-format:
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
name: Format, Lint, Unit Test
runs-on: ubuntu-22.04
steps:
- name: Checkout code into workspace directory
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/env-setup
- name: Check code format
run: npx nx format:check --base=origin/main
- name: Lint source code
run: npm run format:check

build-apps:
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
name: Build Apps
runs-on: ubuntu-22.04
steps:
- name: Checkout code into workspace directory
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/env-setup
- name: Build demo
run: npm run build
85 changes: 85 additions & 0 deletions .github/workflows/pr-merge-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: PR Merge (main)

on:
push:
branches: [main]

env:
WORKSPACE_ROOT: .
ENVIRONMENT: stg

# Cancel redundant workflow runs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pre_job:
name: Run Workflow?
runs-on: ubuntu-22.04
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@master
with:
concurrent_skipping: 'never'
skip_after_successful_duplicate: 'true'
# Changes to paths must be synced with pr-merge*.yml
paths: '[".github/workflows/pr-commit.yml", "apps/**", "backend/**", "libs/**", "*"]'
paths_ignore: '["**/README.md", "skaffold*.yaml"]'

repo-metadata:
name: Get repo metadata
runs-on: ubuntu-latest
outputs:
next_version: ${{ steps.meta.outputs.next_version }}
sha8: ${{ steps.meta.outputs.sha8 }}
repo_slug: ${{ steps.meta.outputs.repo_slug }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- id: meta
uses: ./.github/actions/repo-metadata
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

build-docker-builder-demo-stg:
needs: [pre_job, repo-metadata]
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
name: Builder Demo Staging Image
runs-on: ubuntu-22.04
env:
APP_NAME: builder-demo
BRANCH_NAME: main
steps:
- name: Checkout code into workspace directory
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- name: Build and push staging docker image
id: docker_build
uses: docker/build-push-action@v4
with:
context: ${{env.WORKSPACE_ROOT}}
build-args: |
"LAST_COMMIT_SHA=${{needs.repo-metadata.outputs.sha8}}"
"RELEASE_VERSION=${{needs.repo-metadata.outputs.next_version}}"
push: true
file: ${{env.WORKSPACE_ROOT}}/apps/${{env.APP_NAME}}/Dockerfile
target: stg
platforms: linux/amd64,linux/arm64
tags: |
${{needs.repo-metadata.outputs.repo_slug}}/${{env.ENVIRONMENT}}/${{env.APP_NAME}}:${{env.BRANCH_NAME}}-${{needs.repo-metadata.outputs.sha8}}-${{github.run_number}}
${{needs.repo-metadata.outputs.repo_slug}}/${{env.ENVIRONMENT}}/${{env.APP_NAME}}:latest
Loading

0 comments on commit a14105b

Please sign in to comment.