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