forked from janus-idp/backstage-plugins
-
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.
Signed-off-by: David Festal <dfestal@redhat.com>
- Loading branch information
1 parent
30f90b0
commit c51ca39
Showing
1 changed file
with
124 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,124 @@ | ||
# Copyright 2023 Janus Authors | ||
# | ||
# 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: Publish Backend Plugin Manager | ||
|
||
on: | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
# build the backend plugin manager in the backstage/backstage GitHub repository | ||
name: Main Job | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
repository: backstage/backstage | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 14 | ||
|
||
- name: Get sha of the latest backend-plugin-manager commit | ||
id: get_commit_sha | ||
run: | | ||
echo "COMMIT_ID=$(git log -1 --pretty=format:%H -- packages/backend-plugin-manager)" >> "$GITHUB_OUTPUT" | ||
- name: Test if commit is already published | ||
id: test_commit_already_published | ||
env: | ||
COMMIT_ID: ${{ steps.get_commit_sha.outputs.COMMIT_ID }} | ||
run: | | ||
if [ "_$(npm dist-tag ls @dfatwork-pkgs/backend-plugin-manager | grep -e ^$COMMIT_ID)" != "_" ]; then ALREADY_PUSHED="true"; else ALREADY_PUSHED="false"; fi | ||
echo "ALREADY_PUSHED=$ALREADY_PUSHED"" >> "$GITHUB_OUTPUT" | ||
- name: Get the version of the backend-plugin-manager package | ||
id: get_package_version | ||
run: | | ||
echo "PACKAGE_VERSION=$(node -p "require('./packages/backend-plugin-manager/package.json').version")" >> "$GITHUB_OUTPUT" | ||
- name: Get version to push | ||
id: get_version_to_push | ||
if: steps.test_commit_already_published.outputs.ALREADY_PUSHED == 'false' | ||
env: | ||
COMMIT_VERSION: ${{ steps.get_package_version.outputs.PACKAGE_VERSION }} | ||
run: | | ||
COMMIT_VERSION=0.0.0 | ||
####### TODO: Get LAST_PUSHED_VERSION as the value associated with commit in the test_commit_already_published action. | ||
#LAST_PUSHED_VERSION=0.0.3-janus.3 | ||
COMMIT_MAJOR=$(echo $COMMIT_VERSION | cut -d. -f1) | ||
COMMIT_MINOR=$(echo $COMMIT_VERSION | cut -d. -f2) | ||
COMMIT_PATCH=$(echo $COMMIT_VERSION | cut -d. -f3 | cut -d- -f1) | ||
if [ "$COMMIT_MAJOR.$COMMIT_MINOR.$COMMIT_PATCH" == "$COMMIT_VERSION" ]; then | ||
COMMIT_PRERELEASE="" | ||
else | ||
COMMIT_PRERELEASE=$(echo $COMMIT_VERSION | cut -d- -f2) | ||
fi | ||
if [ -n "$COMMIT_PRERELEASE" ]; then | ||
COMMIT_PATCH=$((COMMIT_PATCH-1)) | ||
fi | ||
PATCH=$((COMMIT_PATCH+1)) | ||
if [ -z "$LAST_PUSHED_VERSION" ]; then | ||
LAST_PUSHED_VERSION=$COMMIT_MAJOR.$COMMIT_MINOR.$PATCH-janus.0 | ||
fi | ||
LAST_PUSHED_MAJOR=$(echo $LAST_PUSHED_VERSION | cut -d. -f1) | ||
LAST_PUSHED_MINOR=$(echo $LAST_PUSHED_VERSION | cut -d. -f2) | ||
LAST_PUSHED_PATCH=$(echo $LAST_PUSHED_VERSION | cut -d. -f3 | cut -d- -f1) | ||
LAST_PUSHED_PRERELEASE_WITHOUT_NUMBER=$(echo $LAST_PUSHED_VERSION | cut -d- -f2 | cut -d. -f1) | ||
LAST_PUSHED_PRERELEASE_NUMBER=$(echo $LAST_PUSHED_VERSION | cut -d- -f2 | cut -d. -f2) | ||
if [ "$COMMIT_MAJOR.$COMMIT_MINOR.$PATCH" == "$LAST_PUSHED_MAJOR.$LAST_PUSHED_MINOR.$LAST_PUSHED_PATCH" ]; then | ||
PRERELEASE="janus.$((LAST_PUSHED_PRERELEASE_NUMBER+1))" | ||
else | ||
PRERELEASE="janus.0" | ||
fi | ||
VERSION=$COMMIT_MAJOR.$COMMIT_MINOR.$PATCH-$PRERELEASE | ||
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" | ||
- name: Update BackendPluginManager package.json with @dfatwork-pkgs scope and version, and make it public | ||
if: steps.test_commit_already_published.outputs.ALREADY_PUSHED == 'false' | ||
env: | ||
VERSION: ${{ steps.get_version_to_push.outputs.VERSION }} | ||
run: | | ||
sed -i "s/\"version\": \".*\"/\"version\": \"$VERSION\"/" packages/backend-plugin-manager/package.json | ||
sed -i "s/\"name\": \"@backstage\/backend-plugin-manager\"/\"name\": \"@dfatwork-pkgs\/backend-plugin-manager\"/" packages/backend-plugin-manager/package.json | ||
sed -i "s/\"private\": true/\"private\": false/" packages/backend-plugin-manager/package.json | ||
- name: Install Dependencies | ||
if: steps.test_commit_already_published.outputs.ALREADY_PUSHED == 'false' | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Build the backend-plugin-manager package | ||
if: steps.test_commit_already_published.outputs.ALREADY_PUSHED == 'false' | ||
run: yarn workspace @dfatwork-pkgs/backend-plugin-manager build | ||
|
||
- name: Publish to NPM with the tag as the commit sha | ||
if: steps.test_commit_already_published.outputs.ALREADY_PUSHED == 'false' | ||
env: | ||
COMMIT_ID: ${{ steps.get_commit_sha.outputs.COMMIT_ID }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: yarn publish --access public --tag $COMMIT_ID |