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

feat: add basic ci #1

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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@v4
with:
version: 9.1.1
- name: Set up NodeJS v20
uses: actions/setup-node@v4
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@v4
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
62 changes: 62 additions & 0 deletions .github/workflows/pr-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: PR Commit
on:
pull_request:
branches: [main]
env:
WORKSPACE_ROOT: .
CACHE_SUFFIX: c # 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", "web/**", "*"]'
paths_ignore: '["**/Readme.md"]'

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: npm run format:check
- name: Lint source code
if: success() || failure()
run: npm run lint
- name: Lint style
if: success() || failure()
run: npm run lint:style

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 web app
run: npm run prod:web:build
99 changes: 99 additions & 0 deletions .github/workflows/pr-merge-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: PR Merge (main)

on:
# push:
# branches: [main]
repository_dispatch:
types: [trigger-workflow]

env:
WORKSPACE_ROOT: .
ENVIRONMENT: stg
CACHE_SUFFIX: c # 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", "web/**", "backend/**", "*"]'
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-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 web app
run: npm run prod:web:build

build-docker-web-stg:
needs: [pre_job, repo-metadata]
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
name: Web Staging Image
runs-on: ubuntu-22.04
env:
APP_NAME: web
BRANCH_NAME: main
steps:
- name: Checkout code into workspace directory
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
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@v5
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
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
68 changes: 68 additions & 0 deletions .github/workflows/pr-merge-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: PR Merge (prod)

on:
push:
branches: [main]
repository_dispatch:
types: [trigger-workflow]

env:
WORKSPACE_ROOT: .
ENVIRONMENT: prod

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

jobs:
pre_job:
# needs: fast_forward_job
name: Run Workflow?
runs-on: ubuntu-22.04
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
if: ${{ github.event_name != 'workflow_dispatch' }}
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", "web/**", "backend/**", "*"]'
paths_ignore: '["**/README.md", "skaffold*.yaml"]'

repo-metadata:
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
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-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 web app
run: npm run prod:web:build
1 change: 0 additions & 1 deletion web/frontend-template/src/components/widgets/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

export { default as Burger } from './Burger.vue'
3 changes: 1 addition & 2 deletions web/frontend-template/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

const app = createApp(App)
.use(router)
const app = createApp(App).use(router)

app.mount('#app')
2 changes: 1 addition & 1 deletion web/frontend-template/src/util/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './simple-i18n'
export * from './simple-i18n'