Skip to content

Commit

Permalink
[improve-build] Add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
JayaShakthi97 committed Sep 7, 2023
1 parent 79ed286 commit 3d0bf14
Show file tree
Hide file tree
Showing 2 changed files with 266 additions and 0 deletions.
170 changes: 170 additions & 0 deletions .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2022, WSO2 LLC. (https://www.wso2.com).
#
# WSO2 LLC. licenses this file to you 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: Release Workflow

on:
push:
branches: [improve-release-workflow]
paths-ignore:
- "LICENSE"
workflow_dispatch:

env:
GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }}
BOT_USERNAME: ${{ secrets.RELEASE_BOT_USER_NAME }}
BOT_EMAIL: ${{ secrets.RELEASE_BOT_EMAIL }}

jobs:
release:
name: 🚀 Release
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [lts/*]
maven-version: [3.8.6]
java-version: [1.8]
pnpm-version: [8.6.0]
steps:
- name: ⬇️ Checkout
id: checkout
uses: actions/[email protected]
with:
token: ${{ env.GH_TOKEN }}
fetch-depth: 0

- name: 🟢 Setup node
id: setup-node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: ☕ Set up JDK 1.8
id: jdk-setup
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java-version }}

- name: 🦩 Set up Maven
uses: stCarolas/setup-maven@v4
id: mvn-setup
with:
maven-version: ${{ matrix.maven-version }}

- name: 🥡 Setup pnpm
uses: pnpm/[email protected]
with:
version: ${{ matrix.pnpm-version }}
run_install: false

- name: 🎈 Get pnpm store directory
id: get-pnpm-cache-dir
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- name: 🔆 Cache pnpm modules
uses: actions/cache@v3
id: pnpm-cache
with:
path: ${{ steps.get-pnpm-cache-dir.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: 🧩 Install Dependencies
id: install-dependencies
run: pnpm install

- name: 📝 Create settings.xml with Nexus credentials in ~/.m2
run: |
echo '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>nexus-releases</id>
<username>${{ secrets.NEXUS_USERNAME }}</username>
<password>${{ secrets.NEXUS_PASSWORD }}</password>
</server>
<server>
<id>wso2.releases</id>
<username>${{ secrets.NEXUS_USERNAME }}</username>
<password>${{ secrets.NEXUS_PASSWORD }}</password>
</server>
<server>
<id>wso2.snapshots</id>
<username>${{ secrets.NEXUS_USERNAME }}</username>
<password>${{ secrets.NEXUS_PASSWORD }}</password>
</server>
</servers>
<profiles>
<profile>
<id>include-sources</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</settings>' > ~/.m2/settings.xml
- name: 💾 Cache local Maven repository
id: cache-maven-m2
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: 📣 Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
title: "[Release] [GitHub Action] Update package versions"
publish: pnpm publish:packages
version: pnpm version:packages
commit: "[WSO2 Release] [GitHub Action] [Release] [skip ci] update package versions"
env:
GITHUB_TOKEN: ${{ env.GH_TOKEN }}

- name: 🚀 Perform Release
id: perform-release
working-directory: .github/workflows
run: |
PACKAGES="${{ toJson(steps.changesets.outputs.publishedPackages) }}"
bash ./scripts/release.sh "$PACKAGES"
96 changes: 96 additions & 0 deletions .github/workflows/scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env bash

# -------------------------------------------------------------------------------------
#
# Copyright (c) 2022, WSO2 LLC. (https://www.wso2.com).
#
# WSO2 LLC. licenses this file to you 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.
#
# --------------------------------------------------------------------------------------

# -------------------------------------------------------------------------------------
# This script is used to release the packages in the release workflow.
# -------------------------------------------------------------------------------------

SCRIPT_LOCATION="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

# Goes the the project root directory.
goToRootDirectory() {
cd "$SCRIPT_LOCATION/../../../" || exit 1
}

process_console_package() {
goToRootDirectory &&
cd "apps/console/java" || exit 1 &&
local console_release_version
console_release_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT$//')

echo "Releasing console version: $console_release_version"
mvn -Dresume=false -Darguments='-Dadditionalparam=-Xdoclint:none' -Dmaven.test.skip=true release:prepare -B -DscmCommentPrefix="[WSO2 Release] [GitHub Action] [Release] [skip ci] " &&
mvn -Dresume=false -Darguments='-Dadditionalparam=-Xdoclint:none' -Dmaven.test.skip=true release:perform -B --settings ~/.m2/settings.xml
}

process_myaccount_package() {
goToRootDirectory &&
cd "apps/myaccount/java" || exit 1 &&
local myaccount_release_version
myaccount_release_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT$//')

echo "Releasing myaccount version: $myaccount_release_version"
mvn -Dresume=false -Darguments='-Dadditionalparam=-Xdoclint:none' -Dmaven.test.skip=true release:prepare -B -DscmCommentPrefix="[WSO2 Release] [GitHub Action] [Release] [skip ci] " &&
mvn -Dresume=false -Darguments='-Dadditionalparam=-Xdoclint:none' -Dmaven.test.skip=true release:perform -B --settings ~/.m2/settings.xml
}

process_java_apps_package() {
goToRootDirectory &&
cd "identity-apps-core" || exit 1 &&
local java_apps_release_version
java_apps_release_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT$//')

echo "Releasing java-apps version: $java_apps_release_version"
mvn -Dresume=false -Darguments='-Dadditionalparam=-Xdoclint:none' -Dmaven.test.skip=true release:prepare -B -DscmCommentPrefix="[WSO2 Release] [GitHub Action] [Release] [skip ci] " &&
mvn -Dresume=false -Darguments='-Dadditionalparam=-Xdoclint:none' -Dmaven.test.skip=true release:perform -B --settings ~/.m2/settings.xml
}

PACKAGES=$1

if [ -z "$PACKAGES" ]; then
echo "No packages to be released. Exiting..." &&
exit 0
fi

echo "Releasing packages: $PACKAGES"

# Iterate over each package in the JSON array
for package in $(echo "$PACKAGES" | jq -c '.[]'); do
name=$(echo "$package" | jq -r '.name')

case "$name" in
"@wso2is/console")
process_console_package
;;
"@wso2is/myaccount")
process_myaccount_package
;;
"@wso2is/java-apps")
process_java_apps_package
;;
*)
echo "Irrelevent package: $package"
;;
esac
done

# End of script

0 comments on commit 3d0bf14

Please sign in to comment.