forked from LimeChain/Fruzhin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Create a shared GitHub + NPM release workflow. (#25)
# Description Fruzhin-web needs to create both GitHub and NPM releases. This PR implements the CI/CD needed to do that. - What does this PR do? Adds a shared workflow that creates a GitHub tag and optional github release + npm release. - Why are these changes needed? To improve current CI/CD. - How were these changes implemented and what do they affect? Using GitHub actions. Fixes LimeChain#530 ## Checklist: - [X] I have read the [contributing guidelines](https://github.com/LimeChain/Fruzhin/blob/dev/CONTRIBUTING.md). - [X] My PR title matches the [Conventional Commits spec](https://www.conventionalcommits.org/). - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [ ] I have added tests to cover my changes. - [X] All new and existing tests passed.
- Loading branch information
Showing
4 changed files
with
179 additions
and
62 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,144 @@ | ||
name: Create & Release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
tag_name: | ||
description: 'Tag name (e.g. v1.0.0)' | ||
required: true | ||
default: 'v1.0.0' | ||
github_release: | ||
description: 'GitHub release?' | ||
required: true | ||
type: boolean | ||
default: true | ||
npm_release: | ||
description: 'NPM release?' | ||
required: true | ||
type: boolean | ||
default: true | ||
|
||
jobs: | ||
shared-steps: | ||
name: Run shared steps | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check tag format | ||
run: | | ||
TAG_NAME=${{ github.event.inputs.tag_name }} | ||
if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
echo "Invalid tag format: $TAG_NAME. Must follow v[0-9]+.[0-9]+.[0-9]+" | ||
exit 1 | ||
else | ||
echo "Valid tag format: $TAG_NAME" | ||
fi | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: dev | ||
|
||
- name: Write release version | ||
run: | | ||
VERSION=${{ github.event.inputs.tag_name }} | ||
echo "Releasing version: $VERSION" | ||
sed -i -e 's@version = .\d*.\d*.\d*.*@version = "'"$VERSION"'"@g' build.gradle.kts | ||
- name: Create or use provided tag | ||
run: | | ||
# Use provided tag from the input | ||
NEW_TAG=${{ github.event.inputs.tag_name }} | ||
echo "Tag name: $NEW_TAG" | ||
git tag $NEW_TAG | ||
git push origin $NEW_TAG | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up cache for Gradle | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.gradle/caches | ||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
gradle-${{ runner.os }} | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'corretto' | ||
|
||
- name: Build Gradle Project | ||
run: ./gradlew build | ||
|
||
github-release: | ||
name: Create GitHub Release | ||
runs-on: ubuntu-latest | ||
needs: shared-steps | ||
if: ${{ github.event.inputs.github_release == 'true' }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.inputs.tag_name }} | ||
|
||
- name: Build Changelog | ||
id: changelog | ||
uses: requarks/changelog-action@v11 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
token: ${{ github.token }} | ||
tag: ${{ github.event.inputs.tag_name }} | ||
|
||
- name: Create release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.event.inputs.tag_name }} | ||
release_name: Release ${{ github.event.inputs.tag_name }} | ||
body: ${{ steps.changelog.outputs.changes }} | ||
draft: false | ||
prerelease: false | ||
|
||
- name: Upload Release Asset | ||
id: upload-release-asset | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./build/libs/Fruzhin-${{ github.event.inputs.tag_name }}.jar | ||
asset_name: Fruzhin-${{ github.event.inputs.tag_name }}.jar | ||
asset_content_type: application/java-archive | ||
|
||
npm-release: | ||
name: Publish to NPM | ||
runs-on: ubuntu-latest | ||
needs: shared-steps | ||
if: ${{ github.event.inputs.npm_release == 'true' }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.inputs.tag_name }} | ||
|
||
- name: Unzip WAR file | ||
run: | | ||
unzip build/libs/*.war -d dist | ||
rm -rf dist/META-INF dist/WEB-INF dist/index.html | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Install NPM dependencies | ||
run: npm install | ||
|
||
- name: Publish to NPM | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: npm publish |
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,5 @@ | ||
node_modules/ | ||
src/ | ||
.git/ | ||
.env | ||
*.log |
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,30 @@ | ||
{ | ||
"name": "fruzhin-web", | ||
"version": "1.0.0", | ||
"description": "An implementation of Fruzhin's light client usable in the web.", | ||
"main": "./dist/js/fruzhin-lib.js", | ||
"files": [ | ||
"./dist/js", | ||
"./dist/genesis" | ||
], | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/LimeChain/Fruzhin-web.git" | ||
}, | ||
"keywords": [ | ||
"teavm", | ||
"java", | ||
"js", | ||
"npm", | ||
"polkadot" | ||
], | ||
"author": "LimeChain (LimeLabs EOOD)", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/LimeChain/Fruzhin-web/issues" | ||
}, | ||
"homepage": "https://github.com/LimeChain/Fruzhin-web#readme" | ||
} |