Skip to content

Commit c785ae5

Browse files
committed
refc: make release script more modular
1 parent b289236 commit c785ae5

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
"Name": "prettier",
44
"Description": "Format your code using Prettier",
55
"Website": "https://github.com/gamemaker1/micro-plugin-prettier",
6-
"Tags": [
7-
"javascript",
8-
"node",
9-
"nodejs",
10-
"typescript",
11-
"formatting"
12-
],
6+
"Tags": ["javascript", "node", "nodejs", "typescript", "formatting"],
137
"Versions": [
148
{
159
"Version": "0.1.0",

scripts/release

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,73 @@ if [[ -z "$1" ]]; then
1515
exit 1
1616
fi
1717

18-
version="$1"
18+
# The plugin name
19+
plugin_name="prettier"
20+
# The new version
21+
plugin_version="$1"
22+
# The GitHub repo
23+
github_repo="gamemaker1/micro-plugin-prettier"
24+
# The GitHub remote
25+
github_remote="origin"
26+
# The GitHub branch
27+
github_branch="main"
28+
# Space-separated list of files to include in the zip
29+
source_files=("source/prettier.lua")
30+
# The metadata file (should ALWAYS be /repo.json)
31+
metadata_file="repo.json"
1932

2033
# Ensure that there are no unstaged changes
2134
if ! [[ -z "$(git status --porcelain)" ]]; then
2235
echo "[error] Please commit all changes before creating a new release"
2336
exit 1
2437
fi
2538

26-
# Change the version in `source/prettier.lua`
27-
sed -i "s/^VERSION = .*/VERSION = \"$version\"/" source/prettier.lua
39+
# Change the version in the source file
40+
sed -i "s/^VERSION = .*/VERSION = \"$plugin_version\"/" "${source_files[@]}"
2841

29-
# Add a new entry to `assets/metadata.json`
30-
cat assets/metadata.json | jq ".[0].Versions += [
42+
# Add a new entry to `repo.json`
43+
cat "$metadata_file" | jq ".[0].Versions += [
3144
{
32-
\"Version\": \"$version\",
33-
\"Url\": \"https://github.com/gamemaker1/micro-plugin-prettier/releases/download/$version/prettier.zip\",
45+
\"Version\": \"$plugin_version\",
46+
\"Url\": \"https://github.com/$github_repo/releases/download/$plugin_version/$plugin_name.zip\",
3447
\"Require\": {
3548
\"micro\": \">=1.0.3\"
3649
}
3750
}
38-
]" --indent 2 | tee assets/metadata.json
51+
]" --indent 2 | tee "$metadata_file"
3952

40-
echo "[info] Updated version"
53+
echo "[info] Updated version to $plugin_version"
4154

4255
# Commit the changes
4356
git add .
44-
git commit -m "chore(release): $version"
57+
git commit -m "chore(release): $plugin_version"
4558
# Tag the commit
46-
git tag $version
59+
git tag "$plugin_version"
4760

4861
echo "[info] Created and tagged commit"
4962

5063
# Push the commit and tag to GitHub
51-
git push -f origin main
52-
git push -f origin $version
64+
git push -f "$github_remote" "$github_branch"
65+
git push -f "$github_remote" "$plugin_version"
5366

5467
echo "[info] Pushed to Github"
5568

5669
# Create a zip file with files needed by Micro
5770
rm -rf build/
5871
mkdir -p build/ && cd build/
59-
cp ../assets/metadata.json ./repo.json
60-
cp ../source/prettier.lua ./prettier.lua
61-
zip -qr9 prettier.zip ./repo.json ./prettier.lua
72+
cp "../$metadata_file" "./repo.json"
73+
for file in "${source_files[@]}"; do
74+
cp "../$file" "./"
75+
done
76+
zip -qr9 "$plugin_name.zip" ./*
6277
cd ..
6378

6479
echo "[info] Created distributable zip"
6580

6681
# Create a Github Release with the created file
67-
gh release create $version ./build/prettier.zip
82+
gh release create "$plugin_version" "build/$plugin_name.zip" -t "$plugin_version" --notes "See the readme for instructions on how to install, use and configure the plugin. Thanks for using!"
6883

69-
echo "[info] Created a new release ($version)!"
84+
echo "[info] Created a new release ($plugin_version)!"
7085

7186
# Open the release in the browser so we can add the change notes
72-
gh release view -w $version
87+
gh release view -w $plugin_version

0 commit comments

Comments
 (0)