Skip to content

Commit

Permalink
Merge pull request #11 from mtrdesign/ci-cd-2
Browse files Browse the repository at this point in the history
Improve the deploy flow
  • Loading branch information
cvetty authored Jun 27, 2024
2 parents abd0840 + 23777dd commit f735294
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 22 deletions.
6 changes: 0 additions & 6 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[ Please replace this text with a summary of the changes.]

### Ticket(s)

Resolves [ISSUE-xxxxx](https://basecamp.com/1765345/projects/18517146/todos/xxxxx).

## Description

<!--
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ name: Draft Release
on:
push:
branches:
# - main
- ci-cd-1
# paths-ignore:
# - "docs/**"
# - "*.yml"
# - "*.md"
- main

jobs:
draft-release:
Expand Down
79 changes: 71 additions & 8 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ permissions:
contents: write

jobs:
pre-release:
prerelease:
name: Draft Github Release
runs-on: ubuntu-20.04
outputs:
release_id: ${{ steps.update_release.outputs.result }}
steps:
- name: Checkout the repo
uses: actions/checkout@v4
with:
ref: main
lfs: false

- uses: actions/setup-node@v4
- name: Install NodeJS
uses: actions/setup-node@v4
with:
node-version: '18.20.3'
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Setup Vals
- name: Configure github user
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
Expand All @@ -68,7 +68,8 @@ jobs:
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
git push --tags
- name: Set tag
- name: Set release tag
id: update_release
uses: actions/github-script@v6
with:
script: |
Expand Down Expand Up @@ -109,7 +110,69 @@ jobs:
prerelease: true,
body: releaseNotes,
});
return release.id
env:
TAG_NAME: ${{ steps.create_tag.outputs.tag }}
USER: ${{ github.event.sender.login }}
DESCRIPTION: ${{ github.event.inputs.description }}
build_ui:
name: Build UI Library
needs: [prerelease]
runs-on: ubuntu-20.04
permissions:
contents: write
steps:
- name: Checkout the repo
uses: actions/checkout@v4
with:
path: krait-ui

- name: Install NodeJS
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'

- name: Retrieve the npm dependencies cache
uses: actions/cache@v4
id: node-modules-cache
with:
path: node_modules
key: npm-dependencies-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
npm-dependencies-${{ hashFiles('package-lock.json') }}
npm-dependencies-
- name: Install npm dependencies
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: npm ci

- name: Build FE assets
run: npm run build

- name: Zip the distribution build
if: needs.init-environment.outputs.is_deployment_pipeline == 'true'
run: zip -9qry "distribution-package.zip" "./" -i "dist/*" "package.json" "package-lock.json"

- name: Upload an Asset in GitHub Release
uses: actions/github-script@v6
with:
script: |
const {RELEASE_ID} = process.env
const fs = require('fs').promises;
await github.rest.repos.uploadReleaseAsset({
name: 'README.md',
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ env.RELEASE_ID }},
data: await fs.readFile('./npm-dist.zip')
});
env:
RELEASE_ID: ${{ needs.prerelease.outputs.release_id }}

- name: Publish the NPM package
run: npm publish --access public --tag dev
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
90 changes: 90 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Release

on:
release:
types: [released]

env:
NODE_VERSION: "18.15.0"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

permissions:
contents: write

jobs:
check:
name: check
runs-on: ubuntu-20.04
steps:
- name: Checkout the repo
uses: actions/checkout@v4
with:
ref: main
lfs: false

- name: Install NodeJS
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'

- name: Get build url
id: get_distribution_build
run: |
BUILD_URL=$(node .github/scripts/find_build_url.js "$ASSETS")
echo "build_url=$BUILD_URL" >> "$GITHUB_OUTPUT"
echo "$BUILD_URL"
env:
ASSETS: ${{ toJson(github.event.release.assets) }}

- name: Cd to the UI
run: cd krait-ui

- name: Download distribution build
run: curl -O $DOWNLOAD_URL
env:
DOWNLOAD_URL: ${{ steps.get_distribution_build.outputs.build_url }}

- name: Unzip distribution-package.zip
run: unzip -q distribution-package.zip

- name: Setup Vals
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"}
- name: Update package version
id: update_package_version
run: |
RELEASE_VERSION=$(echo "$VERSION" | sed -e 's/-beta\.[[:digit:]_-]\{1,\}//g')
npm version $VERSION
git push
echo "tag=$RELEASE_VERSION" >> "$GITHUB_OUTPUT"
git push --tags
env:
VERSION: ${{ github.event.release.tag_name }}

- name: Publish the NPM package
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

- name: Update release tag
uses: actions/github-script@v6
with:
script: |
const {TAG_NAME, RELEASE_ID} = process.env
github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: RELEASE_ID,
name: TAG_NAME,
tag_name: TAG_NAME,
});
env:
RELEASE_ID: ${{ github.event.release.id }}
TAG_NAME: ${{ steps.update_package_version.outputs.tag }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
1 change: 1 addition & 0 deletions krait-ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
dist/
npm-debug.log
.idea
.DS_Store
4 changes: 2 additions & 2 deletions krait-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f735294

Please sign in to comment.