Skip to content

Commit 52efa3d

Browse files
authored
🥥 [just,readme] justfile supports command line workflow (#2)
1 parent 58073b3 commit 52efa3d

File tree

2 files changed

+108
-6
lines changed

2 files changed

+108
-6
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ A good starting place for new github repos.
1010
## Template Status
1111

1212
-[All github community standards are checked off](https://github.com/fini-net/template-repo/community)
13-
-[gitattributes](.gitattributes)
13+
-[gitattributes](.gitattributes) based on [gitattributes](https://github.com/gitattributes/gitattributes)
1414
-[gitignore](.gitignore) with comments
1515
-[Issue Templates](.github/ISSUE_TEMPLATE)
1616
-[PR Template](.github/pull_request_template.md)
1717
-[CODEOWNERS](.github/CODEOWNERS)
18-
-[justfile](justfile)
18+
-[justfile](justfile) with command line workflow for pull requests
1919
-[Github Action for Markdownlint](.github/workflows)
2020
-[A few extra labels for issues](https://github.com/fini-net/template-repo/labels)
2121

2222
## Usage
2323

24-
1. Make a new repo and use this repo as your template.
24+
1. Make a new repo and use this repo as your template. You might have to fork it first.
2525
1. Remember to replace any `chicks-net`, `fini-net`, and `template-repo` references
2626
with the right values for your project. (Github templates do not offer
27-
variable substitution, but we still have to call them templaes for some reason.)
28-
1. Ditch the "Template Status" and "Usage" sections in the `README.md`.
27+
variable substitution, but we still have to call them templates for some reason.)
28+
1. Ditch the "Template Status", "Usage", and "Kudos" sections in the `README.md`.
2929

3030
## Contibuting
3131

justfile

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,107 @@
11
# project justfile
22

3-
default:
3+
# some useful variables
4+
host := `uname -n`
5+
release_branch := "main"
6+
7+
# thanks to https://stackoverflow.com/a/7293026/2002471 for the perfect git incantation
8+
last_commit_message := `git log -1 --pretty=%B | grep '.'`
9+
10+
# list recipes (default works without naming it)
11+
[group('example')]
12+
list:
413
just --list
514
@echo "{{GREEN}}Your justfile is waiting for more scripts and snippets{{NORMAL}}"
15+
16+
# escape from branch, back to starting point
17+
[group('Process')]
18+
sync:
19+
git checkout main
20+
git pull
21+
git stp
22+
23+
# PR create 3.0
24+
[group('Process')]
25+
pr: on_a_branch
26+
#!/usr/bin/env bash
27+
set -euxo pipefail # strict mode
28+
29+
git stp
30+
git pushup
31+
32+
set +x # leave tracing off...
33+
34+
bodyfile=$(mktemp /tmp/justfile.XXXXXX)
35+
36+
echo "## Done:" >> $bodyfile
37+
echo "" >> $bodyfile
38+
echo "- {{ last_commit_message }}" >> $bodyfile
39+
echo "" >> $bodyfile
40+
echo "" >> $bodyfile
41+
echo "(Automated in \`justfile\`.)" >> $bodyfile
42+
43+
echo ''
44+
cat "$bodyfile"
45+
echo ''
46+
47+
gh pr create --title "{{ last_commit_message }}" --body-file "$bodyfile"
48+
rm "$bodyfile"
49+
50+
if [[ ! -e ".github/workflows" ]]; then
51+
echo "{{BLUE}}there are no workflows in this repo so there are no PR checks to watch{{NORMAL}}"
52+
exit 0
53+
fi
54+
55+
echo "{{BLUE}}sleeping for 10s because github is lazy with their API{{NORMAL}}"
56+
sleep 10
57+
gh pr checks --watch
58+
59+
# merge PR and return to starting point
60+
[group('Process')]
61+
merge:
62+
gh pr merge -s -d
63+
just sync
64+
65+
# start a new branch
66+
[group('Process')]
67+
branch branchname: main_branch
68+
#!/usr/bin/env bash
69+
NOW=`just utcdate`
70+
git co -b "chicks/$NOW-{{ branchname }}"
71+
72+
# view PR in web browser
73+
[group('Process')]
74+
prweb: on_a_branch
75+
gh pr view --web
76+
77+
# error if not on a git branch
78+
[group('sanity check')]
79+
[no-cd]
80+
on_a_branch:
81+
#!/bin/bash
82+
83+
# thanks to https://stackoverflow.com/a/12142066/2002471
84+
85+
if [[ $(git rev-parse --abbrev-ref HEAD) == "main" ]]; then
86+
echo "{{RED}}You are on branch '{{ release_branch }}' (the release branch) so you are not ready to start a PR.{{NORMAL}}"
87+
exit 100
88+
fi
89+
90+
# error if not on the release branch
91+
[group('sanity check')]
92+
[no-cd]
93+
main_branch:
94+
#!/bin/bash
95+
96+
# thanks to https://stackoverflow.com/a/12142066/2002471
97+
98+
if [[ ! $(git rev-parse --abbrev-ref HEAD) == "main" ]]; then
99+
echo "You are on a branch that is not the release branch so you are not ready to start a new branch."
100+
exit 100
101+
fi
102+
103+
# print UTC date in ISO format
104+
[group('Utility')]
105+
[no-cd]
106+
@utcdate:
107+
TZ=UTC date +"%Y-%m-%d"

0 commit comments

Comments
 (0)