forked from caponetto/orchestrator-plugins-internal-release
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublish_notifications.sh
executable file
·70 lines (55 loc) · 2.93 KB
/
publish_notifications.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Inputs
read -p "Enter new version to release: " version
read -p "Enter Organization name on npmjs.com (default: masayag-tests): " npmOrgName
npmOrgName=${npmOrgName:-masayag-tests}
read -p "Enter Organization name on github.com to fetch the code (default: masayag): " githubOrgName
githubOrgName=${githubOrgName:-masayag}
read -p "Enter Repository name on github.com to fetch the code (default: backstage-plugins): " githubRepoName
githubRepoName=${githubRepoName:-backstage-plugins}
read -p "Enter Branch name on github.com to fetch the code (default: main): " githubRefName
githubRefName=${githubRefName:-main}
read -p "Dry run (true/false, default: true): " dryRun
dryRun=${dryRun:-true}
# Ensure GITHUB_TOKEN and NPM_TOKEN are set in your environment variables
# Checkout backstage-plugins
git clone https://github.com/$githubOrgName/$githubRepoName=.git --branch $githubRefName --depth 1
# Get the commit hash
commit_hash=$(git -C $githubRepoName rev-parse HEAD)
echo "Commit Hash: $commit_hash"
# Setup Node.js (ensure Node.js and Yarn are installed)
cd $githubRepoName
# Install dependencies
yarn --prefer-offline --frozen-lockfile
# Update the package version
echo "Update version of plugins/notifications and plugins/notifications-backend to $version"
(cd plugins/notifications && yarn version --new-version $version --no-git-tag-version)
(cd plugins/notifications-backend && yarn version --new-version $version --no-git-tag-version)
# Replace the package organization name
old_string="@janus-idp/plugin-notifications"
new_string="@$npmOrgName/plugin-notifications"
grep -rl "$old_string" | xargs sed -i "s|$old_string|$new_string|g"
old_string='janus-idp\.plugin-notifications'
new_string="$npmOrgName\.plugin-notifications"
grep -rl "$old_string" | xargs sed -i "s|$old_string|$new_string|g" || true
# Refresh dependencies
yarn --prefer-offline --frozen-lockfile
# Build the packages
echo "Build plugins/notifications and plugins/notifications-backend"
(cd plugins/notifications && yarn tsc && yarn build && yarn export-dynamic)
(cd plugins/notifications-backend && yarn tsc && yarn build && yarn export-dynamic)
# Delete exports property from notifications-backend/dist-dynamic
jq 'del(.exports)' plugins/notifications-backend/dist-dynamic/package.json > temp.json && mv temp.json plugins/notifications-backend/dist-dynamic/package.json
# Publish packages to npmjs.com
if [ "$dryRun" = false ]; then
echo "Publishing packages to npmjs.com"
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
folders=("plugins/notifications" "plugins/notifications-backend" "plugins/notifications-backend/dist-dynamic")
for folder in "${folders[@]}"; do
(cd $folder && npm publish --access public)
done
fi
# Publish the release on GitHub (requires GitHub CLI - gh)
if [ "$dryRun" = false ]; then
gh release create "$version" --title "$version" --notes "Commit from $githubOrgName/$githubRepoName @ $githubRefName\n$commit_hash"
fi