Skip to content

Commit bd543bd

Browse files
authored
Create new repo with workflow dispatch (#1)
1 parent b3f8ad2 commit bd543bd

File tree

3 files changed

+106
-39
lines changed

3 files changed

+106
-39
lines changed

.github/workflows/makenew.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
name: Make New
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
codeowner:
8+
description: Your GitHub username (my-user)
9+
required: true
10+
repo:
11+
description: GitHub repository name (new-repo)
12+
required: true
13+
slug:
14+
description: Package name (@seamapi/new-package)
15+
required: true
16+
title:
17+
description: Package title (New Package)
18+
required: true
19+
description:
20+
description: Short package description (Foos and bars.)
21+
required: true
22+
23+
jobs:
24+
repository:
25+
name: Create new repository
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 30
28+
steps:
29+
- name: Create repository
30+
run: gh repo create --internal $REPO
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
33+
REPO: seamapi/${{ github.event.inputs.repo }}
34+
bootstrap:
35+
name: Bootstrap code
36+
runs-on: ubuntu-latest
37+
timeout-minutes: 30
38+
needs: repository
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v3
42+
with:
43+
ref: main
44+
fetch-depth: 0
45+
token: ${{ secrets.GH_TOKEN }}
46+
- name: Import GPG key
47+
uses: crazy-max/ghaction-import-gpg@v5
48+
with:
49+
git_user_signingkey: true
50+
git_commit_gpgsign: true
51+
git_committer_name: ${{ secrets.GIT_USER_NAME }}
52+
git_committer_email: ${{ secrets.GIT_USER_EMAIL }}
53+
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
54+
passphrase: ${{ secrets.GPG_PASSPHRASE }}
55+
- name: Replace makenew boilerplate
56+
run: ./makenew.sh
57+
env:
58+
CI: 'true'
59+
mk_codeowner: ${{ github.event.inputs.codeowner }}
60+
mk_repo: ${{ github.event.inputs.repo }}
61+
mk_slug: ${{ github.event.inputs.slug }}
62+
mk_title: ${{ github.event.inputs.title }}
63+
mk_description: ${{ github.event.inputs.description }}
64+
- name: Commit
65+
uses: stefanzweifel/git-auto-commit-action@v4
66+
with:
67+
commit_message: Replace makenew boilerplate
68+
commit_user_name: ${{ secrets.GIT_USER_NAME }}
69+
commit_user_email: ${{ secrets.GIT_USER_EMAIL }}
70+
commit_author: ${{ secrets.GIT_USER_NAME }} <${{ secrets.GIT_USER_EMAIL }}>
71+
- name: Push
72+
run: |
73+
git remote add origin $ORIGIN
74+
git push -u origin main
75+
env:
76+
ORIGIN: [email protected]:seamapi/${{ github.event.inputs.repo }}.git
77+
version:
78+
name: Cut initial version
79+
runs-on: ubuntu-latest
80+
timeout-minutes: 30
81+
needs: bootstrap
82+
steps:
83+
- name: Cut version
84+
run: gh workflow run version.yml --repo $REPO --raw-field version=patch
85+
env:
86+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
87+
REPO: seamapi/${{ github.event.inputs.repo }}

README.md

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,13 @@ Bootstrap a new TypeScript module in five minutes or less.
5151

5252
### Bootstrapping a new project
5353

54-
1. Create an empty (**non-initialized**) repository on GitHub.
55-
2. Clone the main branch of this repository with
56-
```
57-
$ git clone --single-branch [email protected]:seamapi/makenew-tsmodule.git <new-ts-module>
58-
$ cd <new-ts-module>
59-
```
60-
Optionally, reset to the latest version with
61-
```
62-
$ git reset --hard <version-tag>
63-
```
64-
3. Run
65-
```
66-
$ ./makenew.sh
67-
```
68-
This will replace the boilerplate, delete itself,
69-
remove the git remote, remove upstream tags,
70-
and stage changes for commit.
71-
4. Create the required GitHub repository secrets.
72-
5. Review, commit, and push the changes to GitHub with
73-
```
74-
$ git diff --cached
75-
$ git commit -m "Replace makenew boilerplate"
76-
$ git remote add origin [email protected]:<user>/<new-node-lib>.git
77-
$ git push -u origin main
78-
```
79-
6. Ensure the GitHub action passes,
80-
then publish the initial version of the package with
81-
```
82-
$ gh workflow run version.yml --raw-field version=patch
83-
```
54+
1. [Trigger a makenew workflow from this repository][makenew workflow]. 🚀
55+
- Provide a value for each required input.
56+
- There are no defaults.
57+
- Example values are shown in parentheses.
58+
2. When the workflow completes, clone your new repo and start coding!
59+
60+
[makenew workflow]: https://github.com/seamapi/makenew-tsmodule/actions/workflows/makenew.yml
8461

8562
### Updating from this skeleton
8663

makenew.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ stage_env () {
3737
git remote rm origin
3838
echo
3939
git rm -f makenew.sh
40+
git rm -f .github/workflows/makenew.yml
4041
echo
4142
echo 'Staging changes.'
4243
git add --all
@@ -46,16 +47,18 @@ stage_env () {
4647
}
4748

4849
makenew () {
49-
echo 'Answer all prompts.'
50-
echo 'There are no defaults.'
51-
echo 'Example values are shown in parentheses.'
52-
read -p '> Your GitHub username (my-user): ' mk_codeowner
53-
read -p '> Package title (My Package): ' mk_title
54-
read -p '> Package name (@seamapi/my-package): ' mk_slug
55-
read -p '> Short package description (Foos and bars.): ' mk_description
56-
read -p '> GitHub repository name (my-repo): ' mk_repo
50+
if [[ -z "${CI:-}" ]]; then
51+
echo 'Answer all prompts.'
52+
echo 'There are no defaults.'
53+
echo 'Example values are shown in parentheses.'
54+
read -p '> Your GitHub username (my-user): ' mk_codeowner
55+
read -p '> GitHub repository name (new-repo): ' mk_repo
56+
read -p '> Package name (@seamapi/new-package): ' mk_slug
57+
read -p '> Package title (New Package): ' mk_title
58+
read -p '> Short package description (Foos and bars.): ' mk_description
59+
fi
5760

58-
sed_delete README.md '9,101d'
61+
sed_delete README.md '9,78d'
5962
sed_insert README.md '9i' 'TODO'
6063

6164
find_replace "s/^ \"version\": \".*\"/ \"version\": \"0.0.0\"/g"

0 commit comments

Comments
 (0)