forked from caponetto/orchestrator-plugins-internal-release
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublish_orchestrator.sh
executable file
·135 lines (114 loc) · 4.76 KB
/
publish_orchestrator.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# Define usage function
usage() {
echo "Usage: $0 [-v <version>] [-n <npmOrgName>] [-g <githubOrgName>] [-p <githubRepoName>] [-r <githubRefName>] [-d <dryRun>]" 1>&2
exit 1
}
# Set default values
VERSION=""
NPM_ORG_NAME="masayag-tests"
GITHUB_ORG_NAME="masayag"
GITHUB_REPO_NAME="backstage-plugins"
GITHUB_REF_NAME="main"
DRY_RUN="true"
# Parse options
while getopts ":v:n:g:p:r:d:" opt; do
case $opt in
v) VERSION="$OPTARG";;
n) NPM_ORG_NAME="$OPTARG";;
g) GITHUB_ORG_NAME="$OPTARG";;
p) GITHUB_REPO_NAME="$OPTARG";;
r) GITHUB_REF_NAME="$OPTARG";;
d) DRY_RUN="$OPTARG";;
*) usage;;
esac
done
# Validate options
if [ -z "$VERSION" ]; then
echo "Error: Version is required."
usage
fi
echo Using:
echo VERSION=$VERSION
echo NPM_ORG_NAME=$NPM_ORG_NAME
echo GITHUB_ORG_NAME=$GITHUB_ORG_NAME
echo GITHUB_REPO_NAME=$GITHUB_REPO_NAME
echo GITHUB_REF_NAME=$GITHUB_REF_NAME
echo DRY_RUN=$DRY_RUN
# Get commit hash
COMMIT_HASH=$(git rev-parse HEAD)
# Checkout backstage-plugins
git clone --depth=1 --branch="$GITHUB_REF_NAME" "https://github.com/$GITHUB_ORG_NAME/$GITHUB_REPO_NAME.git"
# Setup Node.js
NODE_VERSION="18.x"
curl -fsSL https://deb.nodesource.com/setup_"$NODE_VERSION" | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm install -g yarn
# Install dependencies
cd $GITHUB_REPO_NAME
yarn --prefer-offline --frozen-lockfile
cd plugins/orchestrator-common
current_version_common_package=$(node -p "require('./package.json').version")
cd -
echo "current_version_common_package= $current_version_common_package"
# Update package version
for folder in "plugins/orchestrator-common" "plugins/orchestrator" "plugins/orchestrator-backend"; do
echo "Update version of $folder"
cd "$folder"
yarn version --new-version "$VERSION" --no-git-tag-version
sed -i 's/"@janus-idp\/backstage-plugin-orchestrator-common": "'"$current_version_common_package"'"/"@janus-idp\/backstage-plugin-orchestrator-common": "'"$VERSION"'"/g' package.json
git diff ./package.json
cd -
done
# Replace the package organization name
old_string='@janus-idp/backstage-plugin-orchestrator'
new_string="@${NPM_ORG_NAME}/backstage-plugin-orchestrator"
grep -rl "$old_string" | xargs sed -i "s|$old_string|$new_string|g"
old_string='janus-idp\.backstage-plugin-orchestrator'
new_string="${NPM_ORG_NAME}.backstage-plugin-orchestrator"
grep -rl "$old_string" | xargs sed -i "s|$old_string|$new_string|g"
# Print package names and versions
for folder in "plugins/orchestrator-common" "plugins/orchestrator" "plugins/orchestrator-backend"; do
echo "Package name: $(node -p "require('./$folder/package.json').name")"
echo "Package version: $(node -p "require('./$folder/package.json').version")"
done
# Refresh dependencies
yarn --prefer-offline --frozen-lockfile
# Build the packages
for folder in "plugins/orchestrator-common" "plugins/orchestrator" "plugins/orchestrator-backend"; do
echo "Build $folder"
cd "$folder"
yarn tsc && yarn build && [[ "$folder" != "plugins/orchestrator-common" ]] && yarn export-dynamic
cd -
done
# Delete exports property from orchestrator-backend/dist-dynamic
cd plugins/orchestrator-backend/dist-dynamic
jq 'del(.exports)' package.json > temp.json && mv temp.json package.json
cd -
# Publish packages to npmjs.com
if [ "$DRY_RUN" != true ]; then
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc
for folder in "plugins/orchestrator-common" "plugins/orchestrator" "plugins/orchestrator-backend" "plugins/orchestrator-backend/dist-dynamic"; do
cd "$folder"
npm publish --access public
cd -
done
fi
# Collect integrity hashes
if [ "$DRY_RUN" != true ]; then
package="@${NPM_ORG_NAME}/backstage-plugin-orchestrator"
integrity=$(curl -s "https://registry.npmjs.org/$package" | jq -r ".versions[\"$VERSION\"].dist.integrity")
backstage_plugin_orchestrator=$integrity
package="@${NPM_ORG_NAME}/backstage-plugin-orchestrator-backend-dynamic"
integrity=$(curl -s "https://registry.npmjs.org/$package" | jq -r ".versions[\"$VERSION\"].dist.integrity")
backstage_plugin_orchestrator_backend_dynamic=$integrity
fi
# Publish the release on GitHub
if [ "$DRY_RUN" != true ]; then
tag="$VERSION"
name="$VERSION"
body="### Commit from '$GITHUB_ORG_NAME/$GITHUB_REPO_NAME @ $GITHUB_REF_NAME'\n'$COMMIT_HASH'\n### Packages\n- @${NPM_ORG_NAME}/backstage-plugin-orchestrator ('$backstage_plugin_orchestrator')\n- @${NPM_ORG_NAME}/backstage-plugin-orchestrator-backend-dynamic ('$backstage_plugin_orchestrator_backend_dynamic')"
curl -X POST https://api.github.com/repos/$GITHUB_ORG_NAME/$GITHUB_REPO_NAME/releases \
-H "Authorization: token $GITHUB_TOKEN" \
-d "{\"tag_name\":\"$tag\",\"name\":\"$name\",\"body\":\"$body\"}"
fi