浏览代码

ci: auto update description in "package.json"

ci: auto update badges in README
ci: improve writing in comments
Paul Razvan Berg 2 年之前
父节点
当前提交
890b858dd8
共有 2 个文件被更改,包括 40 次插入17 次删除
  1. 16 4
      .github/scripts/rename.sh
  2. 24 13
      .github/workflows/create.yml

+ 16 - 4
.github/scripts/rename.sh

@@ -4,23 +4,35 @@
 set -euo pipefail
 
 # Define the input vars
-GITHUB_REPOSITORY=${1?Error: Please pass username/repo, e.g. prb/hardhat-template}
+GITHUB_REPOSITORY=${1?Error: Please pass username/repo, e.g. prb/foundry-template}
 GITHUB_REPOSITORY_OWNER=${2?Error: Please pass username, e.g. prb}
+GITHUB_REPOSITORY_DESCRIPTION=${3:-""} # If null then replace with empty string
 
 echo "GITHUB_REPOSITORY: $GITHUB_REPOSITORY"
 echo "GITHUB_REPOSITORY_OWNER: $GITHUB_REPOSITORY_OWNER"
+echo "GITHUB_REPOSITORY_DESCRIPTION: $GITHUB_REPOSITORY_DESCRIPTION"
 
 # 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 )' \
+  --arg DESCRIPTION "$GITHUB_REPOSITORY_DESCRIPTION" \
+  '.name = $NAME | .description = $DESCRIPTION | .author |= ( .name = $AUTHOR_NAME | .url = $URL )' \
   package.json
 `
 
 # Overwrite package.json
 echo "$JQ_OUTPUT" > package.json
 
-# Rename instances of "paulrberg/hardhat-template" to the new repo name in README.md for badges only
-sed -i -e "/Use this template/! s|paulrberg/hardhat-template|"${GITHUB_REPOSITORY}"|;" "README.md"
+# 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"

+ 24 - 13
.github/workflows/create.yml

@@ -1,33 +1,44 @@
-name: Create
+name: "Create"
 
-# The workflow will run only when `use this template` is used
+# The workflow will run only when the "Use this template" button 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
+    # We only run this action when the repository isn't the template repository. References:
+    # - https://docs.github.com/en/actions/learn-github-actions/contexts
+    # - https://docs.github.com/en/actions/learn-github-actions/expressions
     if: ${{ !github.event.repository.is_template }}
-
-    runs-on: ubuntu-latest
-    permissions: write-all
-
+    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"
+        env:
+          GITHUB_REPOSITORY_DESCRIPTION: ${{ github.event.repository.description }}
+        run:
+          ./.github/scripts/rename.sh "$GITHUB_REPOSITORY" "$GITHUB_REPOSITORY_OWNER" "$GITHUB_REPOSITORY_DESCRIPTION"
 
       - name: "Add rename summary"
         run: |
-          echo "## Commit results" >> $GITHUB_STEP_SUMMARY
+          echo "## Commit result" >> $GITHUB_STEP_SUMMARY
+          echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
+
+      - name: "Remove `rename.sh` and `create.yml`"
+        run: |
+          rm -f "./.github/scripts/rename.sh"
+          rm -f "./.github/workflows/create.yml"
+
+      - name: "Add remove summary"
+        run: |
+          echo "## Remove result" >> $GITHUB_STEP_SUMMARY
           echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
 
       - name: "Update commit"
-        uses: stefanzweifel/git-auto-commit-action@v4
+        uses: "stefanzweifel/git-auto-commit-action@v4"
         with:
           commit_message: "feat: initial commit"
           commit_options: "--amend"
@@ -36,5 +47,5 @@ jobs:
 
       - name: "Add commit summary"
         run: |
-          echo "## Commit results" >> $GITHUB_STEP_SUMMARY
+          echo "## Commit result" >> $GITHUB_STEP_SUMMARY
           echo "✅ Passed" >> $GITHUB_STEP_SUMMARY