From 947522e4fa0926479211fa97a6492cebc420130a Mon Sep 17 00:00:00 2001 From: sripwoud Date: Thu, 11 Jul 2024 09:26:54 +0200 Subject: [PATCH] ci: update publish-for-forge.sh --- .github/workflows/release.yml | 2 +- scripts/publish-for-forge.sh | 46 +++++++++++++++-------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b6048a8..3968b4a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -51,5 +51,5 @@ jobs: steps: - uses: actions/checkout@v4 - uses: fregante/setup-git-user@v2.0.1 - - name: Push contracts to dedicated branches + - name: Push contracts to forge branch run: scripts/publish-for-forge.sh diff --git a/scripts/publish-for-forge.sh b/scripts/publish-for-forge.sh index 983f98d..e810104 100755 --- a/scripts/publish-for-forge.sh +++ b/scripts/publish-for-forge.sh @@ -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