Skip to content

Commit

Permalink
fix: reuse workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewPattell committed Jul 13, 2023
1 parent 026edd9 commit 7f79ef8
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 169 deletions.
63 changes: 63 additions & 0 deletions .github/test/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: SSR BOOST Build

on:
workflow_call:
inputs:
node-version:
required: false
type: string
default: 18.13.0
app-build-args:
required: false
type: string
docker-file:
required: false
type: string
default: node_modules/@lomray/vite-ssr-boost/workflow/Dockerfile
secrets:
GITHUB_TOKEN:
required: false

jobs:
build:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.ref }}-build
cancel-in-progress: true

steps:
- uses: actions/checkout@v3

- run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc

- uses: actions/setup-node@v3
with:
node-version: ${{ inputs.config-path }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run eslint
run: npm run lint:check

- name: Typescript check
run: npm run ts:check

- name: Stylelint check
run: npm run style:check

- name: Build application
run: |
npm pkg delete scripts.prepare
npm run build -- ${{ inputs.app-build-args }}
- name: Archive build
uses: actions/upload-artifact@v3
with:
name: build-artifact
path: |
build
package.json
package-lock.json
${{ inputs.docker-file }}
60 changes: 60 additions & 0 deletions .github/test/deploy-aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: SSR BOOST Deploy AWS

on:
workflow_call:
inputs:
image:
required: true
type: string
service:
required: true
type: string
cluster:
required: true
type: string
task-container-name:
required: true
type: string
task-definition:
required: false
type: string
default: .github/task-definition.json
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
AWS_REGION:
required: true

jobs:
deploy-aws:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.ref }}-deploy-aws
cancel-in-progress: true

steps:
- uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Update AWS ECS Task Definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ inputs.task-definition }}
container-name: ${{ inputs.task-container-name }}
image: ${{ inputs.image }}

- name: Deploy AWS ECS Task Definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ inputs.service }}
cluster: ${{ inputs.cluster }}
67 changes: 67 additions & 0 deletions .github/test/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: SSR BOOST Docker build

on:
workflow_call:
inputs:
registry:
required: true
type: string
image-name:
required: true
type: string
version:
required: true
type: string
app-build-path:
required: true
type: string
secrets:
GITHUB_TOKEN:
required: true

jobs:
docker-build:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.ref }}-build-docker
cancel-in-progress: true
outputs:
# get docker image tag with version
image-tag: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}

steps:
- uses: actions/download-artifact@v3
with:
name: build-artifact

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2

- name: Log into registry
uses: docker/login-action@v2
with:
registry: ${{ inputs.registry }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ inputs.registry }}/${{ inputs.image-name }}
tags: |
type=raw,prefix={{branch}}-,value=${{ inputs.version }}
type=raw,prefix=latest-,value={{branch}}
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILD_PATH=${{ inputs.app-build-path }}
44 changes: 44 additions & 0 deletions .github/test/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: SSR BOOST Release

on:
workflow_call:
inputs:
has-release-asset:
required: false
type: boolean
default: false
secrets:
GITHUB_TOKEN:
required: true

jobs:
release:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.ref }}-release
cancel-in-progress: true
outputs:
version: ${{ steps.package-version.outputs.version }}

steps:
- uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with:
name: build-artifact

- name: Create release asset
if: ${{ inputs.has-release-asset }}
run: zip -r build.zip build package.json package-lock.json README.md

- name: Install dependencies
run: npm ci

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release

- name: Get version
id: package-version
run: npx @lomray/microservices-cli package-version
7 changes: 5 additions & 2 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ name: Check PR

on:
pull_request:
branches: [ prod, staging ]
branches: [ prod ]
types: [ synchronize ]

env:
NODE_VERSION: 18.13.0

jobs:
check:
runs-on: ubuntu-latest
Expand All @@ -19,7 +22,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: '18.13.0'
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'

- name: Install dependencies
Expand Down
Loading

0 comments on commit 7f79ef8

Please sign in to comment.