Bläddra i källkod

refactor: update README when spinning up template

Ahmed Ali 3 år sedan
förälder
incheckning
97548dd2ee
4 ändrade filer med 79 tillägg och 6 borttagningar
  1. 26 0
      .github/scripts/rename.sh
  2. 6 4
      .github/workflows/ci.yml
  3. 43 0
      .github/workflows/create.yml
  4. 4 2
      README.md

+ 26 - 0
.github/scripts/rename.sh

@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+
+# https://gist.github.com/vncsna/64825d5609c146e80de8b1fd623011ca
+set -euo pipefail
+
+# Define the input vars
+REPOSITORY=${1?Error: Please pass username/repo, e.g. prb/hardhat-template}
+REPOSITORY_OWNER=${2?Error: Please pass username, e.g. prb}
+
+echo "REPOSITORY: $REPOSITORY"
+echo "REPOSITORY_OWNER: $REPOSITORY_OWNER"
+
+# jq is like sed for JSON data
+JQ_OUTPUT=`jq \
+  --arg NAME "@$REPOSITORY" \
+  --arg AUTHOR_NAME "$REPOSITORY_OWNER" \
+  --arg URL "https://github.com/$REPOSITORY_OWNER" \
+  '.name = $NAME | .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|"${REPOSITORY}"|;" "README.md"

+ 6 - 4
.github/workflows/ci.yml

@@ -1,9 +1,5 @@
 name: "CI"
 
-env:
-  INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}
-  MNEMONIC: ${{ secrets.MNEMONIC }}
-
 on:
   pull_request:
     branches:
@@ -25,6 +21,12 @@ jobs:
           cache: "yarn"
           node-version: "16"
 
+      # Inject all environment variables from ".env.example" in $GITHUB_ENV
+      - name: "Set dotenv"
+        uses: "c-py/action-dotenv-to-setenv@v2"
+        with:
+          env-file: ".env.example"
+
       - name: "Install the dependencies"
         run: "yarn install --immutable"
 

+ 43 - 0
.github/workflows/create.yml

@@ -0,0 +1,43 @@
+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 }}
+
+    runs-on: ubuntu-latest
+    permissions: write-all
+
+    steps:
+      - name: "Check out the repo"
+        uses: "actions/checkout@v3"
+
+      - name: "Update package.json"
+        env:
+          REPOSITORY: ${{ github.repository }}
+          REPOSITORY_OWNER: ${{ github.repository_owner }}
+        run: ./.github/scripts/rename.sh "$REPOSITORY" "$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

+ 4 - 2
README.md

@@ -1,5 +1,7 @@
-# Hardhat Template [![Github Actions][gha-badge]][gha] [![Hardhat][hardhat-badge]][hardhat] [![License: MIT][license-badge]][license]
+# Hardhat Template [![Open in Gitpod][gitpod-badge]][gitpod] [![Github Actions][gha-badge]][gha] [![Hardhat][hardhat-badge]][hardhat] [![License: MIT][license-badge]][license]
 
+[gitpod]: https://gitpod.io/#https://github.com/paulrberg/hardhat-template
+[gitpod-badge]: https://img.shields.io/badge/Gitpod-Open%20in%20Gitpod-FFB45B?logo=gitpod
 [gha]: https://github.com/paulrberg/hardhat-template/actions
 [gha-badge]: https://github.com/paulrberg/hardhat-template/actions/workflows/ci.yml/badge.svg
 [hardhat]: https://hardhat.org/
@@ -52,7 +54,7 @@ This template comes with sensible default configurations in the following files:
 This template comes with GitHub Actions pre-configured. Your contracts will be linted and tested on every push and pull
 request made to the `main` branch.
 
-Note though that to make this work, you must se your `INFURA_API_KEY` and your `MNEMONIC` as GitHub secrets.
+Note though that to make this work, you must use your `INFURA_API_KEY` and your `MNEMONIC` as GitHub secrets.
 
 You can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci.yml).