Skip to content

Commit

Permalink
feat(devops): allow update from template repo
Browse files Browse the repository at this point in the history
  • Loading branch information
arifbalik committed Aug 13, 2024
1 parent 1e7bac6 commit 9ba2523
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ npm install
There are a few npm scripts that you can use to maintain your monorepo:

- `npm run reset-repo` resets the repository to the default settings
- `npm run update-from-template` updates the repository from the template (`arifbalik/monorepo`)
- `npm run signingkey path/to/signingkey.pub` configures git to use ssh signing key to sign commits
- `npm run commitlint` runs commitlint on the repository
- `npm run lint` runs megalinter on the repository
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"scripts": {
"reset-repo": "sh scripts/reset-repo-settings.sh",
"update-from-template": "git fetch --all && git merge --allow-unrelated-histories template/main",
"signingkey": "git config --global commit.gpgsign true && git config --global gpg.format ssh && git config --global user.signingkey",
"commitlint": "commitlint --edit",
"lint": "npx mega-linter-runner --fix",
Expand Down
10 changes: 9 additions & 1 deletion scripts/reset-repo-settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

# Common headers and endpoint
headers="-H Accept:application/vnd.github+json -H X-GitHub-Api-Version:2022-11-28"
repo_endpoint="repos/{owner}/{repo}"
owner=$(gh api user | jq -r .login)
repo=$(git config --get remote.origin.url | sed -E 's/.*\/([^/]+)\.git/\1/')
repo_endpoint="repos/$owner/$repo"

# Repository settings
repo_settings='{
Expand Down Expand Up @@ -112,3 +114,9 @@ if [ -n "$ruleset_id" ]; then
fi

echo "$rules" | gh api --method POST $headers "$repo_endpoint/rulesets" --input -

# Check if the remote 'template' exists, if not add it
if ! git remote | grep -q '^template$'; then
git remote add template https://github.com/arifbalik/monorepo.git
fi
gh repo set-default "$owner/$repo"

0 comments on commit 9ba2523

Please sign in to comment.