Skip to content

Commit

Permalink
Add release tools (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
rnijveld authored Nov 24, 2023
1 parent d4c3d2c commit 9baf2c5
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/man/statime.toml.5.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- ---
title: STATIME.TOML(5) statime 1.0.0 | statime
title: STATIME.TOML(5) statime 0.1.0 | statime
--- -->

# NAME
Expand Down
2 changes: 1 addition & 1 deletion docs/precompiled/man/statime.toml.5
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
. ftr VB CB
. ftr VBI CBI
.\}
.TH "STATIME.TOML" "5" "" "statime 1.0.0" "statime"
.TH "STATIME.TOML" "5" "" "statime 0.1.0" "statime"
.hy
.SH NAME
.PP
Expand Down
132 changes: 132 additions & 0 deletions utils/prepare-artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/bin/env bash

set -eo pipefail

print_help() {
echo "Usage: utils/prepare-artifacts.sh OPTIONS"
echo ""
echo "Options:"
echo " --[no-]reset Clear the pkg directory or not (default: no)"
echo " --[no-]delete-zips Delete the downloaded zip files or not (default: no)"
echo " --[no-]download-artifacts Download the artifacts or not (default: no)"
echo " --api-token TOKEN The Github API token for downloading artifacts"
echo " --run-id ID The id of the Workflow run for which to download artifacts"
}

GITHUB_API_TOKEN=
RUN_ID=
TARGET_DIR="target/pkg"
DO_RESET=false
DELETE_ZIPS=false
DOWNLOAD_ARTIFACTS=false
ZIP_DOWNLOADS_FOLDER="$TARGET_DIR/zips"


while [[ $# -gt 0 ]]; do
case $1 in
--reset)
DO_RESET=true
;;
--no-reset)
DO_RESET=false
;;
--delete-zips)
DELETE_ZIPS=true
;;
--no-delete-zips)
DELETE_ZIPS=false
;;
--download-artifacts)
DOWNLOAD_ARTIFACTS=true
;;
--no-download-artifacts)
DOWNLOAD_ARTIFACTS=false
;;
--api-token)
GITHUB_API_TOKEN="$2"
shift
;;
--run-id)
RUN_ID="$2"
shift
;;
--help)
print_help
exit 0
;;
esac
shift
done

if [ "$DOWNLOAD_ARTIFACTS" = true ] && ([ -z "$GITHUB_API_TOKEN" ] || [ -z "$RUN_ID" ]); then
if [ -z "$GITHUB_API_TOKEN" ]; then
echo "ERROR: Missing Github API token"
fi

if [ -z "$RUN_ID" ]; then
echo "ERROR: Missing github workflow run id"
fi
print_help
exit 1
fi

if [ "$DO_RESET" = true ]; then
echo "Resetting target dir"
rm -rf "$TARGET_DIR"
fi

mkdir -p "$ZIP_DOWNLOADS_FOLDER"

if [ "$DOWNLOAD_ARTIFACTS" = true ]; then
echo "Retrieving artifacts from run"
artifacts_json=$(curl -L \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer $GITHUB_API_TOKEN" \
https://api.github.com/repos/pendulum-project/statime/actions/runs/$RUN_ID/artifacts)

echo "Extracting artifact urls"
artifact_urls=$(echo "$artifacts_json" | jq -r '.artifacts[] | (.name + ";" + .archive_download_url)')

echo "Download artifacts"
while read artifact; do
IFS=';' read -r name url <<< "$artifact"
echo "Downloading artifact '$name' from '$url'"
zipfile="$ZIP_DOWNLOADS_FOLDER/$name.zip"
curl -L \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer $GITHUB_API_TOKEN" \
-o "$zipfile" "$url"
done < <(echo "$artifact_urls")
echo "Downloads complete"
fi

for f in $(find "$ZIP_DOWNLOADS_FOLDER" -type f); do
echo "Extracting downloaded zip file '$f'"
unzip -d "$TARGET_DIR" "$f"
done

if [ "$DELETE_ZIPS" = true ]; then
echo "Delete the downloaded zips"
rm -rf "$ZIP_DOWNLOADS_FOLDER"
else
echo "Not deleting any downloaded zips"
fi

echo "Flatten file structure"
find "$TARGET_DIR" -mindepth 2 -type f -not -path "$ZIP_DOWNLOADS_FOLDER/*" -exec mv -t "$TARGET_DIR" -i '{}' +

echo "Remove any leftover directories"
find "$TARGET_DIR" -mindepth 1 -type d -not -path "$ZIP_DOWNLOADS_FOLDER" -exec rm -Rf '{}' +

echo "Replace tildes by dashes for github"
for f in $(find "$TARGET_DIR" -type f); do
newf=$(echo "$f" | sed 's/~/-/g')
if [ "$f" != "$newf" ]; then
mv "$f" "$newf"
fi
done

echo "Create SHA256SUMS"
(cd "$TARGET_DIR" && rm -rf "SHA256SUMS" && find * -type f -not -name "SHA256SUMS" -exec sha256sum -b {} + | tee "SHA256SUMS")
4 changes: 4 additions & 0 deletions utils/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

cargo publish -p statime
cargo publish -p statime-linux
42 changes: 42 additions & 0 deletions utils/update-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

if [ "$#" -lt 1 ]; then
echo "Missing new version specifier"
exit 1
fi

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
PROJECT_DIR=$(dirname "$SCRIPT_DIR")
NEW_VERSION="$1"
NOTICE_LINE="# NOTE: keep this part at the bottom of the file, do not change this line"

echo "Updating version in Cargo.toml"
sed -i 's/^version\s*=\s*".*"/version = "'"$NEW_VERSION"'"/' "$PROJECT_DIR/Cargo.toml"

echo "Updating workspace crate versions in Cargo.toml"
tmp_file="$PROJECT_DIR/Cargo.toml.tmp"
replace_flag=0
while IFS= read -r line; do
if [ $replace_flag -eq 1 ]; then
line=$(echo "$line" | sed 's/version\s*=\s*"[^"]*"/version = "'"$NEW_VERSION"'"/g')
fi

if [ "$line" = "$NOTICE_LINE" ]; then
replace_flag=1
fi

echo "$line" >> "$tmp_file"
done < "$PROJECT_DIR/Cargo.toml"
mv "$tmp_file" "$PROJECT_DIR/Cargo.toml"

echo "Updating version in man pages"
sed -i 's/^title: STATIME(8) statime .*/title: STATIME(8) statime '"$NEW_VERSION"' | statime/' "$PROJECT_DIR"/docs/man/statime.8.md
sed -i 's/^title: STATIME.TOML(5) statime .*/title: STATIME.TOML(5) statime '"$NEW_VERSION"' | statime/' "$PROJECT_DIR"/docs/man/statime.toml.5.md

echo "Rebuilding precompiled man pages"
utils/generate-man.sh

echo "Rebuilding project"
(cd $PROJECT_DIR && cargo clean && cargo build --release)

echo "!!! Version changes complete, make sure that the changelog is synchronized"

0 comments on commit 9baf2c5

Please sign in to comment.