From 3013aa4e958fdaa471a0e7f7de789883ae68716e Mon Sep 17 00:00:00 2001 From: cvetty Date: Thu, 27 Jun 2024 21:01:27 +0300 Subject: [PATCH 1/3] Improve the deploy flow --- .github/workflows/draft-release.yml | 7 +- .github/workflows/pre-release.yml | 72 ++++++++++++- .github/workflows/release.yml | 162 ++++++++++++++++++++++++++++ 3 files changed, 230 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index f8d1d6e..2db78a8 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -3,12 +3,7 @@ name: Draft Release on: push: branches: -# - main - - ci-cd-1 -# paths-ignore: -# - "docs/**" -# - "*.yml" -# - "*.md" + - main jobs: draft-release: diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 73213bc..21d73db 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -30,19 +30,18 @@ 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 with: - node-version: '18.20.3' + node-version: ${{ env.NODE_VERSION }} registry-url: 'https://registry.npmjs.org' - name: Install dependencies @@ -69,6 +68,7 @@ jobs: git push --tags - name: Set tag + id: update_release uses: actions/github-script@v6 with: script: | @@ -109,7 +109,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 "npm-dist.zip" "./" -i "dist/*" + + - 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 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0d250e5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,162 @@ +name: Prerelease + +on: + release: + types: [published] + +env: + NODE_VERSION: "18.15.0" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +permissions: + contents: write + +jobs: + deploy_release: + name: Deploy release + runs-on: ubuntu-20.04 + outputs: + release_id: ${{ steps.update_release.outputs.result }} + steps: + - name: Checkout the repo + uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: npm ci + + - 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 + if: github.event.inputs.version-update != 'no update' + run: + npm version $VERSION_UPDATE --no-git-tag-version + env: + VERSION_UPDATE: ${{ github.event.inputs.version-update }} + + - name: Update the beta version + id: create_tag + run: | + TAG=$(npm version prerelease --preid=beta -m "[GHA] Update package version to %s") + git push + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + git push --tags + + - name: Set tag + id: update_release + uses: actions/github-script@v6 + with: + script: | + const {TAG_NAME, USER, DESCRIPTION} = process.env + const releases = await github.rest.repos.listReleases({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: "unreleased", + }) + const filtered = releases.data.filter(release => release.draft == true && release.tag_name === 'unreleased'); + let release; + if (filtered.length === 0) { + console.log("Creating a new untagged release") + release = await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: "unreleased", + name: "Unreleased", + draft: true, + generate_release_notes: true, + }) + } else { + release = filtered[0]; + } + + let releaseNotes = `${USER} released version ${TAG_NAME}.`; + if (DESCRIPTION) { + releaseNotes += `\n\n Release Notes:\n${DESCRIPTION}`; + } + + github.rest.repos.updateRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: release.id, + name: TAG_NAME, + tag_name: TAG_NAME, + draft: false, + 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 "npm-dist.zip" "./" -i "dist/*" + + - 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 }} From c98f1a3c8046ad5fb3218ce21bfd26854b87aef4 Mon Sep 17 00:00:00 2001 From: cvetty Date: Thu, 27 Jun 2024 21:04:04 +0300 Subject: [PATCH 2/3] Improve the PR template --- .github/pull_request_template.md | 6 -- .github/workflows/pre-release.yml | 9 +- .github/workflows/release.yml | 162 +++++++++--------------------- .gitignore | 1 + krait-ui/.gitignore | 1 + krait-ui/package-lock.json | 4 +- krait-ui/package.json | 2 +- 7 files changed, 55 insertions(+), 130 deletions(-) create mode 100644 .gitignore diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index efa7bb3..59dc577 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -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