-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from debugger24/feature/add-ci-cd
Add CI/CD for release
- Loading branch information
Showing
5 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
repo=$1 | ||
release_version=$2 | ||
token=$3 | ||
|
||
echo "Checking release version ${release_version} exists or not." | ||
|
||
exists=$( | ||
curl -s \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${token}" \ | ||
https://api.github.com/repos/${repo}/releases/tags/${release_version} | | ||
jq 'has("id")' | ||
) | ||
|
||
if [[ "$exists" == true ]]; then | ||
echo "Release ${release_version} already exists." | ||
echo '::set-output name=release_exists::true' | ||
else | ||
echo '::set-output name=release_exists::false' | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
repo=$1 | ||
tag_name=$2 | ||
token=$3 | ||
|
||
sha=$( | ||
curl -s \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${token}" \ | ||
https://api.github.com/repos/${repo}/git/ref/tags/${tag_name} | | ||
jq '.object.sha' --raw-output | ||
) | ||
echo "::set-output name=sha::$sha" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
repo=$1 | ||
source_tag_sha=$2 | ||
major_version=$3 | ||
token=$4 | ||
|
||
curl -s \ | ||
-X PATCH -L \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${token}" \ | ||
https://api.github.com/repos/${repo}/git/refs/tags/${major_version} \ | ||
-d '{"sha": "'$source_tag_sha'", "force":true}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
name: Release | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- "main" | ||
paths-ignore: | ||
- "docs/**" | ||
- README.md | ||
- CHANGELOG.md | ||
- .gitignore | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
name: Build | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 12 | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build package | ||
run: npm run build | ||
|
||
- name: Verify build | ||
run: .github/scripts/verify-build.sh | ||
|
||
release-check: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
name: Release Precheck | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get version | ||
id: get-version | ||
run: | | ||
version=$(cat package.json | jq '.version' --raw-output) | ||
echo "Version: v${version}" | ||
echo "::set-output name=version::v${version}" | ||
- name: Check if release exists | ||
id: release-check | ||
run: | | ||
.github/scripts/check-release.sh \ | ||
${{ github.repository }} \ | ||
${{ steps.get-version.outputs.version }} \ | ||
${{ secrets.GITHUB_TOKEN }} | ||
- name: Display warning if release exists | ||
if: steps.release-check.outputs.release_exists == 'true' | ||
run: echo "::warning title=Skipping Release::Release ${release_version} already exists. If you want to create new release please update the version in package.json" | ||
|
||
outputs: | ||
version: ${{ steps.get-version.outputs.version }} | ||
release_exists: ${{ steps.release-check.outputs.release_exists }} | ||
|
||
release: | ||
runs-on: ubuntu-latest | ||
needs: release-check | ||
name: Release | ||
if: needs.release-check.outputs.release_exists == 'false' | ||
steps: | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
name: ${{ needs.release-check.outputs.version }} | ||
tag_name: ${{ needs.release-check.outputs.version }} | ||
generate_release_notes: true | ||
|
||
major_version_update: | ||
name: Major Release | ||
needs: [release, release-check] | ||
uses: ./.github/workflows/major-release.yaml | ||
with: | ||
TAG_NAME: ${{ needs.release-check.outputs.version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: Update Major Release | ||
|
||
on: | ||
release: | ||
types: | ||
- published | ||
|
||
workflow_dispatch: | ||
inputs: | ||
TAG_NAME: | ||
description: "Tag name that the major tag will point to" | ||
required: true | ||
type: string | ||
|
||
workflow_call: | ||
inputs: | ||
TAG_NAME: | ||
description: "Tag name that the major tag will point to" | ||
required: true | ||
type: string | ||
|
||
env: | ||
TAG_NAME: ${{ github.event.release.tag_name || inputs.TAG_NAME }} | ||
|
||
jobs: | ||
update_major_tag: | ||
runs-on: ubuntu-latest | ||
name: Update Major Tag | ||
environment: major-release-update | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get major release version | ||
id: get-major-version | ||
run: | | ||
echo "Tag name: ${TAG_NAME}" | ||
major_version=${TAG_NAME%.*.*} | ||
echo "Major Version: ${major_version}" | ||
echo "::set-output name=major_version::$major_version" | ||
- name: Check if major version exists | ||
id: check-release | ||
run: | | ||
.github/scripts/check-release.sh \ | ||
${{ github.repository }} \ | ||
${{ steps.get-major-version.outputs.major_version }} \ | ||
${{ secrets.GITHUB_TOKEN }} | ||
- name: Get Source Tag SHA | ||
id: source-tag-sha | ||
run: | | ||
.github/scripts/source-tag-sha.sh \ | ||
${{ github.repository }} \ | ||
${{ steps.get-major-version.outputs.major_version }} \ | ||
${{ secrets.GITHUB_TOKEN }} | ||
- name: Create Major Release | ||
uses: softprops/action-gh-release@v1 | ||
if: steps.check-release.outputs.release_exists == 'false' | ||
id: create_release | ||
with: | ||
name: ${{ steps.get-major-version.outputs.major_version }} | ||
tag_name: ${{ steps.get-major-version.outputs.major_version }} | ||
target_commitish: ${{ steps.source-tag-sha.outputs.sha }} | ||
|
||
- name: Update Major tag | ||
if: steps.check-release.outputs.release_exists == 'true' | ||
run: | | ||
.github/scripts/update-major-tag.sh \ | ||
${{ github.repository }} \ | ||
${{ steps.source-tag-sha.outputs.sha }} \ | ||
${{ steps.get-major-version.outputs.major_version }} \ | ||
${{ secrets.GITHUB_TOKEN }} |