Skip to content

Commit

Permalink
ci: update publish-for-forge.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
sripwoud committed Jul 11, 2024
1 parent 9ffc7e4 commit 947522e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: fregante/[email protected]
- name: Push contracts to dedicated branches
- name: Push contracts to forge branch
run: scripts/publish-for-forge.sh
46 changes: 19 additions & 27 deletions scripts/publish-for-forge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,39 @@
set -eu

clean() {
pkg="$1"
# TODO: use regex instead
find . -maxdepth 2 \
find . -maxdepth 1 \
! -path . \
! -path ./.git \
! -path "./.git/*" \
! -path ./.gitignore \
! -path ./packages \
! -path ./LICENSE \
! -path "./packages/$pkg" \
-exec rm -rf {} +
}

maybe_publish_forge_pkg() {
pkg="$1"
version=$(jq -r '.version' "packages/$pkg/package.json")
latest_commit_msg=$(git log -1 --pretty=%B)

git checkout -b "$pkg"
# return early if latest already published
[ "$latest_commit_msg" = "$version" ] && return
git pull --rebase origin "$pkg" 2>/dev/null || true
clean "$pkg"
mkdir "$pkg"
mv "packages/$pkg"/src "$pkg"
mv "packages/$pkg"/README.md "$pkg"
mv LICENSE "$pkg"
rm -fr "packages"
git add "$pkg"
git commit -am "$version"
git push origin "$pkg"
git checkout origin/"$GITHUB_HEAD_REF"
}

main() {
git fetch origin "$GITHUB_HEAD_REF"
git fetch origin main
latest_main_commit_msg=$(git log origin/main -1 --pretty=%B)

git checkout -b forge
git fetch origin forge
git pull origin forge --rebase || true

clean

# http://mywiki.wooledge.org/BashFAQ/001
# https://github.com/koalaman/shellcheck/wiki/SC2012
find packages -maxdepth 1 -mindepth 1 -printf '%P\n' | while read -r pkg; do
maybe_publish_forge_pkg "$pkg"
mkdir "$pkg"
mv "packages/$pkg/src" "$pkg"
mv "packages/$pkg/README.md" "$pkg"
git add "$pkg"
done

rm -fr "packages"

git commit -am "$latest_main_commit_msg"
git push origin forge
}

main

0 comments on commit 947522e

Please sign in to comment.