Add rename script and GitPod badge (#5)

* docs: add gitpod badge

* chore: add "rename.sh" script

update README badges and package.json when spinning up template

* ci: add "create.yml" github action

automatically update README badges and package.json with new <user/repo-name> when spinning up the
template and commits "feat: initial commit"

* ci: polish "create.yml" script

Co-authored-by: Paul Razvan Berg <hello@paulrberg.com>
This commit is contained in:
Ahmed Ali 2022-10-04 15:21:35 +05:00 committed by GitHub
parent e5f2f4a795
commit fc7320c454
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 1 deletions

35
.github/scripts/rename.sh vendored Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
# https://gist.github.com/vncsna/64825d5609c146e80de8b1fd623011ca
set -euo pipefail
# Define the input vars
GITHUB_REPOSITORY=${1?Error: Please pass username/repo, e.g. prb/foundry-template}
GITHUB_REPOSITORY_OWNER=${2?Error: Please pass username, e.g. prb}
echo "GITHUB_REPOSITORY: $GITHUB_REPOSITORY"
echo "GITHUB_REPOSITORY_OWNER: $GITHUB_REPOSITORY_OWNER"
# jq is like sed for JSON data
JQ_OUTPUT=`jq \
--arg NAME "@$GITHUB_REPOSITORY" \
--arg AUTHOR_NAME "$GITHUB_REPOSITORY_OWNER" \
--arg URL "https://github.com/$GITHUB_REPOSITORY_OWNER" \
'.name = $NAME | .description = "" | .author |= ( .name = $AUTHOR_NAME | .url = $URL )' \
package.json
`
# Overwrite package.json
echo "$JQ_OUTPUT" > package.json
# Make sed command compatible in both Mac and Linux environments
# Reference: https://stackoverflow.com/a/38595160/8696958
sedi () {
sed --version >/dev/null 2>&1 && sed -i -- "$@" || sed -i "" "$@"
}
# Rename instances of "paulrberg/foundry-template" to the new repo name in README.md for badges only
sedi "/gitpod/ s|paulrberg/foundry-template|"${GITHUB_REPOSITORY}"|;" "README.md"
sedi "/gitpod-badge/ s|paulrberg/foundry-template|"${GITHUB_REPOSITORY}"|;" "README.md"
sedi "/gha/ s|paulrberg/foundry-template|"${GITHUB_REPOSITORY}"|;" "README.md"
sedi "/gha-badge/ s|paulrberg/foundry-template|"${GITHUB_REPOSITORY}"|;" "README.md"

38
.github/workflows/create.yml vendored Normal file
View File

@ -0,0 +1,38 @@
name: "Create"
# The workflow will run only when `use this template` is used
on:
create:
jobs:
create:
# We will only run this action when the repository isn't the template repository
# Reference https://docs.github.com/en/actions/learn-github-actions/contexts
# Reference https://docs.github.com/en/actions/learn-github-actions/expressions
if: ${{ !github.event.repository.is_template }}
permissions: "write-all"
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: "actions/checkout@v3"
- name: "Update package.json"
run: ./.github/scripts/rename.sh "$GITHUB_REPOSITORY" "$GITHUB_REPOSITORY_OWNER"
- name: "Add rename summary"
run: |
echo "## Commit results" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
- name: "Update commit"
uses: "stefanzweifel/git-auto-commit-action@v4"
with:
commit_message: "feat: initial commit"
commit_options: "--amend"
push_options: "--force"
skip_fetch: true
- name: "Add commit summary"
run: |
echo "## Commit results" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY

View File

@ -1,5 +1,7 @@
# Foundry Template [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![License: MIT][license-badge]][license]
# Foundry Template [![Open in Gitpod][gitpod-badge]][gitpod] [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![License: MIT][license-badge]][license]
[gitpod]: https://gitpod.io/#https://github.com/paulrberg/foundry-template
[gitpod-badge]: https://img.shields.io/badge/Gitpod-Open%20in%20Gitpod-FFB45B?logo=gitpod
[gha]: https://github.com/paulrberg/foundry-template/actions
[gha-badge]: https://github.com/paulrberg/foundry-template/actions/workflows/ci.yml/badge.svg
[foundry]: https://getfoundry.sh/