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(ci): add release workflow #273

Merged
merged 1 commit into from
Mar 1, 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
179 changes: 179 additions & 0 deletions .github/workflows/flow-deploy-release-artifact.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
##
# Copyright (C) 2023-2024 Hedera Hashgraph, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##

name: 'Deploy Release Artifact'
on:
workflow_dispatch:
inputs:
dry-run-enabled:
description: 'Perform Dry Run'
type: boolean
required: false
default: false

defaults:
run:
shell: bash

permissions:
id-token: write
checks: write
statuses: write
pull-requests: write
contents: write
issues: write
actions: read

jobs:
prepare-release:
name: Release / Prepare
runs-on: [self-hosted, Linux, medium, ephemeral]
outputs:
version: ${{ steps.tag.outputs.version }}
steps:
- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 20

- name: Install Semantic Release
run: |
npm install -g [email protected] @semantic-release/[email protected] @semantic-release/[email protected] [email protected]
npm install -g [email protected] @commitlint/[email protected] @commitlint/[email protected]
npm install -g [email protected] [email protected] [email protected]

- name: Calculate Next Version
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_USER_NAME }}
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
GIT_COMMITTER_NAME: ${{ secrets.GIT_USER_NAME }}
GIT_COMMITTER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
run: npx semantic-release --dry-run

- name: Extract Version
id: tag
run: |
[[ "${{ github.event.inputs.dry-run-enabled }}" == true && ! -f VERSION ]] && echo -n "0.0.0-latest" > VERSION
echo "version=$(cat VERSION | tr -d '[:space:]')" >> ${GITHUB_OUTPUT}

safety-checks:
name: Release
uses: ./.github/workflows/zxc-compile-code.yaml
with:
custom-job-label: 'Safety Checks'
enable-unit-tests: true
enable-e2e-tests: true
enable-code-style-check: true

create-github-release:
name: Github / Release
runs-on: [self-hosted, Linux, medium, ephemeral]
needs:
- prepare-release
- safety-checks
steps:
- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
token: ${{ secrets.GH_ACCESS_TOKEN }}
fetch-depth: 0

- name: Install GnuPG Tools
run: |
if ! command -v gpg2 >/dev/null 2>&1; then
echo "::group::Updating APT Repository Indices"
sudo apt update
echo "::endgroup::"
echo "::group::Installing GnuPG Tools"
sudo apt install -y gnupg2
echo "::endgroup::"
fi

- name: Import GPG key
id: gpg_key
uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0
with:
gpg_private_key: ${{ secrets.GPG_KEY_CONTENTS }}
passphrase: ${{ secrets.GPG_KEY_PASSPHRASE }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
git_tag_gpgsign: false

- name: Setup Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 20

- name: Setup JFrog CLI
uses: jfrog/setup-jfrog-cli@26da2259ee7690e63b5410d7451b2938d08ce1f9 # v4.0.0
env:
JF_URL: ${{ vars.JF_URL }}
JF_ACCESS_TOKEN: ${{ secrets.JF_ACCESS_TOKEN }}

- name: Show JFrog Config
run: jfrog config show

- name: Verify JFrog Connectivity
run: jfrog rt ping

- name: Setup JFrog NPM Repository
run: |
jf npmc --server-id-resolve setup-jfrog-cli-server --server-id-deploy setup-jfrog-cli-server --repo-resolve hedera-cli-npm-release --repo-deploy hedera-cli-npm-release
echo "::group::JFrog NPM Repository Configuration"
cat .jfrog/projects/npm.yaml
echo "::endgroup::"

- name: Install Semantic Release
run: |
npm install -g [email protected] @semantic-release/[email protected] @semantic-release/[email protected] [email protected]
npm install -g [email protected] @commitlint/[email protected] @commitlint/[email protected]
npm install -g [email protected] [email protected] [email protected]

- name: Install Dependencies
run: jf npm ci

- name: Compile Code
run: npm run build

- name: Setup NPM Authentication
run: |
# create .npmrc file to publish Hedera CLI to the npmjs.org registry
rm -f .npmrc || true
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > ".npmrc"
echo '@hashgraph:registry=https://registry.npmjs.org/' >> ".npmrc"

- name: Publish Semantic Release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_USER_NAME }}
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
GIT_COMMITTER_NAME: ${{ secrets.GIT_USER_NAME }}
GIT_COMMITTER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
if: ${{ github.event.inputs.dry-run-enabled != 'true' && !cancelled() && !failure() }}
run: npx semantic-release

- name: Deploy to JFrog Registry
if: ${{ github.event.inputs.dry-run-enabled != 'true' && !cancelled() && !failure() }}
run: jf npm publish
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,6 @@ junit*.xml

# Exclude E2E/Unit test generated state files
src/state/state.json

# Exclude semantic-release version info
VERSION
62 changes: 62 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits"
}
],
"@semantic-release/npm",
"@semantic-release/git",
"@semantic-release/github"
],
"verifyRelease": [
[
"@semantic-release/exec",
{ "cmd": "echo ${nextRelease.version} > VERSION" }
]
],
"prepare": [
"@semantic-release/npm",
[
"@semantic-release/git",
{
"assets": [
"package.json",
"package-lock.json"
]
}
]
],
"branches":[
{
"name": "main"
},
{
"name": "release/([0-9]+).([0-9]+)",
"channel": "${name.replace(/release\\//g, '').split('.')[0]}.${name.replace(/release\\//g, '').split('.')[1]}.x",
"range": "${name.replace(/release\\//g, '').split('.')[0]}.${name.replace(/release\\//g, '').split('.')[1]}.x"
},
{
"name": "alpha/*",
"prerelease": "alpha",
"channel": "alpha"
},
{
"name": "ci/*",
"prerelease": "alpha",
"channel": "alpha"
},
{
"name": "beta/*",
"prerelease": "beta",
"channel": "beta"
},
{
"name": "rc/*",
"prerelease": "rc",
"channel": "rc"
}
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hedera-cli",
"version": "1.0.0",
"name": "@hashgraph/hedera-cli",
"version": "0.0.0",
"description": "CLI tool to manage and setup developer environments for Hedera Hashgraph.",
"main": "hedera-cli.js",
"target": "esnext",
Expand Down