From 3047f95ec9fd2a746d3b23ad2c88ca8200d19b3c Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Fri, 5 Apr 2024 15:41:59 -0400 Subject: [PATCH] Fi 2432 Sync Inferno Template (#439) * add draft publish_template.sh * add Inferno version command * add Inferno version rspec * rubocop conformance * remove force push * test script * add tmp folder to git, but ignore files in tmp * make script use tmp folder and push to branch * make publish_template rename tmp/inferno-template instead of removing it * clean script * config rubocop to ignore tmp/ * fix typo * add github access token env option for publish_template script to put up a PR * remove +x from publish_template * improve publish_template.sh end messages * fix comments * mv publish_template.sh scripts/publish_template * debug --- .gitignore | 4 ++- .rubocop.yml | 1 + scripts/publish_template | 55 ++++++++++++++++++++++++++++++++++++++++ tmp/.keep | 0 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100755 scripts/publish_template create mode 100644 tmp/.keep diff --git a/.gitignore b/.gitignore index e9f559d36..4968608d5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,9 @@ /lib/inferno/public/*.LICENSE.txt /lib/inferno/public/*.png !/lib/inferno/public/logo*.png -/tmp +!/tmp +/tmp/* +!/tmp/.keep .env.local .env.*.local **/.DS_Store diff --git a/.rubocop.yml b/.rubocop.yml index d6d7cdc15..50c8cd944 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,6 +10,7 @@ AllCops: - 'Gemfile' - 'vendor/**/*' - 'lib/inferno/db/schema.rb' + - 'tmp/**/*' Layout/LineLength: Max: 120 diff --git a/scripts/publish_template b/scripts/publish_template new file mode 100755 index 000000000..29f6fae37 --- /dev/null +++ b/scripts/publish_template @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +# +# Push a new Inferno version to inferno-template GitHub Repository via SSH. +# +# USAGE: +# ./publish_template +# OR +# ./publish_template [github/ssh/url] +# OR +# GITHUB_ACCESS_TOKEN="PUT_YOUR_TOKEN_HERE" ./publish_template + +set -e + + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +REPO_URL=${1:-git@github.com:inferno-framework/inferno-template.git} +VERSION=$(bundle exec $SCRIPT_DIR/../bin/inferno version) +TITLE="Update $VERSION" +BRANCH=$(echo $TITLE | tr ' [:upper:]' '-[:lower:]') + +cd "$SCRIPT_DIR/../tmp" +git clone $REPO_URL ./inferno-template +git -C ./inferno-template branch $BRANCH +git -C ./inferno-template checkout $BRANCH + +rm -f ./inferno-template/Gemfile.lock + +bundle exec ../bin/inferno new inferno-template --author "Inferno Template" --force + +git -C ./inferno-template add --all +git -C ./inferno-template commit --message "Update to $VERSION" +git -C ./inferno-template push --set-upstream origin $BRANCH +mv ./inferno-template "./inferno-template-$BRANCH" +cd - + +if [[ ! -z "${GITHUB_ACCESS_TOKEN}" ]]; then + ENDPOINT=${REPO_URL%.git} + ENDPOINT=${ENDPOINT#git@github.com:} + + curl \ + --request POST \ + --header "Content-type: application/json" \ + --header "Authorization: Bearer ${GITHUB_ACCESS_TOKEN}" \ + --header "X-GitHub-Api-Version: 2022-11-28" \ + --data "{ \"title\":\"$TITLE\", \"head\":\"${BRANCH}\", \"base\":\"main\"}" \ + "https://api.github.com/repos/$ENDPOINT/pulls" + echo "Put up pull request: $TITLE. Please merge it to main." + echo "You can troubleshoot changes locally at tmp/inferno-template-$BRANCH" +else + echo "No GITHUB_ACCESS_TOKEN found, skipping pull request" + echo "Committed changes to active branch $BRANCH" + echo "Pushed changes to remote branch on origin" + echo "You can troubleshoot changes locally at tmp/inferno-template-$BRANCH" + echo "Please put up a pull request manually" +fi diff --git a/tmp/.keep b/tmp/.keep new file mode 100644 index 000000000..e69de29bb