Skip to content

Commit 52f2e97

Browse files
authored
🦿 [just] update just from template-repo (#12)
1 parent a6f803c commit 52f2e97

File tree

3 files changed

+215
-39
lines changed

3 files changed

+215
-39
lines changed

‎.just/compliance.just‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# our own compliance check
2+
[group('Compliance')]
3+
compliance_check:
4+
#!/usr/bin/env bash
5+
set -euo pipefail # strict mode without tracing
6+
7+
echo "{{BLUE}}Chicks' repo compliance check...{{NORMAL}}"
8+
9+
if [[ -e README.md ]]; then
10+
echo "{{GREEN}}You have a README.md, thank you.{{NORMAL}}"
11+
else
12+
echo "{{RED}}You do NOT have a README.md, hmmmm, why is this repo here?{{NORMAL}}"
13+
fi
14+
15+
if [[ -e LICENSE ]]; then
16+
echo "{{GREEN}}[gh] You have a license, good for you.{{NORMAL}}"
17+
else
18+
echo "{{RED}}[gh] You do NOT have a license, are you feeling ok?{{NORMAL}}"
19+
fi
20+
21+
if [[ -e .github/CODE_OF_CONDUCT.md ]]; then
22+
echo "{{GREEN}}[gh] You have a Code of Conduct, respect.{{NORMAL}}"
23+
else
24+
echo "{{RED}}[gh] You do NOT have a Code of Conduct. So anything goes around here?{{NORMAL}}"
25+
fi
26+
27+
if [[ -e .github/CONTRIBUTING.md ]]; then
28+
echo "{{GREEN}}[gh] You have a Contributing Guide, how giving.{{NORMAL}}"
29+
else
30+
echo "{{RED}}[gh] You do NOT have a Contributing Guide. Hopefully they'll figure it out on their own.{{NORMAL}}"
31+
fi
32+
33+
if [[ -e .github/SECURITY.md ]]; then
34+
echo "{{GREEN}}[gh] You have a Security Guide, very comforting.{{NORMAL}}"
35+
else
36+
echo "{{RED}}[gh] You do NOT have a Security Guide. Don't call the cops.{{NORMAL}}"
37+
fi
38+
39+
if [[ -e .github/pull_request_template.md ]]; then
40+
echo "{{GREEN}}[gh] You have a pull request template, not too pushy.{{NORMAL}}"
41+
else
42+
echo "{{RED}}[gh] You do NOT have a pull request template. Prepare for anything.{{NORMAL}}"
43+
fi
44+
45+
if [[ -d .github/ISSUE_TEMPLATE ]]; then
46+
echo "{{GREEN}}[gh] You have Issue Templates, life is good.{{NORMAL}}"
47+
else
48+
echo "{{RED}}[gh] You do NOT have Issue Templates. I must take issue with that.{{NORMAL}}"
49+
fi
50+
51+
if [[ $(gh repo view --json description | jq -r '.description' | wc -c) -gt 16 ]]; then
52+
echo "{{GREEN}}[gh] You have a repo description, more evidence that you are undescribable.{{NORMAL}}"
53+
else
54+
echo "{{RED}}[gh] You do NOT have a repo description, can you write a word or two please?{{NORMAL}}"
55+
fi
56+
57+
# github also checks for something about the repo admins
58+
59+
if [[ -e .github/CODEOWNERS ]]; then
60+
echo "{{GREEN}}You have a CODEOWNERS file, in DEED.{{NORMAL}}"
61+
else
62+
echo "{{RED}}You do NOT have a CODEOWNERS file. Does anyone want to make a claim?{{NORMAL}}"
63+
fi
64+
65+
if [[ -e .gitignore ]]; then
66+
echo "{{GREEN}}You have a .gitignore file, so there will be less debris in your future.{{NORMAL}}"
67+
else
68+
echo "{{RED}}You do NOT have a .gitignore file. I expect you to keep ignoring my advice!{{NORMAL}}"
69+
fi
70+
71+
if [[ -e .gitattributes ]]; then
72+
echo "{{GREEN}}You have a .gitattributes file, keeping metadata and line endings clean too.{{NORMAL}}"
73+
else
74+
echo "{{RED}}You do NOT have a .gitattributes file. Did you hear what happens when binaries and text files get together?{{NORMAL}}"
75+
fi
76+
77+
if [[ -e justfile ]]; then
78+
echo "{{GREEN}}You have a {{BLUE}}justfile{{GREEN}}, spreading justice and automation a little further.{{NORMAL}}"
79+
else
80+
echo "{{RED}}You do NOT have a justfile. Feeling the FOMO yet?{{NORMAL}}"
81+
echo "{{RED}}And this should not be possible. Tell me how you got here.{{NORMAL}}"
82+
fi
83+
84+
if [[ -e .editorconfig ]]; then
85+
echo "{{GREEN}}You have an {{BLUE}}.editorconfig{{GREEN}}, keeping tabs and spaces segregated.{{NORMAL}}"
86+
else
87+
echo "{{RED}}You do NOT have an .editorconfig. Will your world explode when the tabs and spaces get together?{{NORMAL}}"
88+
fi

‎.just/gh-process.just‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# git/gh process justfile
2+
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+
# escape from branch, back to starting point
11+
[group('Process')]
12+
sync:
13+
git checkout {{ release_branch }}
14+
git pull
15+
git stp
16+
17+
# PR create 3.2
18+
[group('Process')]
19+
pr: _has_commits
20+
#!/usr/bin/env bash
21+
set -euxo pipefail # strict mode
22+
23+
git stp
24+
git pushup
25+
26+
set +x # leave tracing off...
27+
28+
bodyfile=$(mktemp /tmp/justfile.XXXXXX)
29+
30+
echo "## Done:" >> $bodyfile
31+
echo "" >> $bodyfile
32+
echo "- {{ last_commit_message }}" >> $bodyfile
33+
echo "" >> $bodyfile
34+
echo "" >> $bodyfile
35+
echo "(Automated in \`justfile\`.)" >> $bodyfile
36+
37+
echo ''
38+
cat "$bodyfile"
39+
echo ''
40+
41+
gh pr create --title "{{ last_commit_message }}" --body-file "$bodyfile"
42+
rm "$bodyfile"
43+
44+
if [[ ! -e ".github/workflows" ]]; then
45+
echo "{{BLUE}}there are no workflows in this repo so there are no PR checks to watch{{NORMAL}}"
46+
exit 0
47+
fi
48+
49+
echo "{{BLUE}}sleeping for 10s because github is lazy with their API{{NORMAL}}"
50+
sleep 10
51+
gh pr checks --watch -i 5
52+
53+
# merge PR and return to starting point
54+
[group('Process')]
55+
merge: _on_a_branch && sync
56+
gh pr merge -s -d
57+
# `&& sync` is mostly redundant, but just in case
58+
59+
# start a new branch
60+
[group('Process')]
61+
branch branchname: _main_branch
62+
#!/usr/bin/env bash
63+
NOW=`just utcdate`
64+
git co -b "$USER/$NOW-{{ branchname }}"
65+
66+
# view PR in web browser
67+
[group('Process')]
68+
prweb: _on_a_branch
69+
gh pr view --web
70+
71+
# error if not on a git branch
72+
[group('sanity check')]
73+
[no-cd]
74+
_on_a_branch:
75+
#!/bin/bash
76+
77+
# thanks to https://stackoverflow.com/a/12142066/2002471
78+
79+
if [[ $(git rev-parse --abbrev-ref HEAD) == "{{ release_branch }}" ]]; then
80+
echo "{{RED}}You are on branch '{{ release_branch }}' (the release branch) so you are not ready to start a PR.{{NORMAL}}"
81+
exit 100
82+
fi
83+
84+
# error if not on the release branch
85+
[group('sanity check')]
86+
[no-cd]
87+
_has_commits: _on_a_branch
88+
#!/bin/bash
89+
90+
# thanks to https://stackoverflow.com/a/24668421/2002471
91+
92+
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
93+
#echo $CURRENT_BRANCH
94+
95+
if [[ $(git cherry -v {{ release_branch }} "$CURRENT_BRANCH" | wc -l) -eq 0 ]]; then
96+
echo "You are on a branch that {{RED}}does not have any commits{{NORMAL}}."
97+
exit 101
98+
fi
99+
100+
# error if not on the release branch
101+
[group('sanity check')]
102+
[no-cd]
103+
_main_branch:
104+
#!/bin/bash
105+
106+
# thanks to https://stackoverflow.com/a/12142066/2002471
107+
108+
if [[ ! $(git rev-parse --abbrev-ref HEAD) == "{{ release_branch }}" ]]; then
109+
echo "You are on a {{BLUE}}branch that is not the release branch{{NORMAL}} so you are not ready to start a new branch."
110+
exit 102
111+
fi
112+
113+
# print UTC date in ISO format
114+
[group('Utility')]
115+
[no-cd]
116+
@utcdate:
117+
TZ=UTC date +"%Y-%m-%d"
118+
119+
# make a release
120+
[group('Process')]
121+
release rel_version:
122+
gh release create {{rel_version}} --generate-notes

‎justfile‎

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# project justfile
2+
3+
import? '.just/compliance.just'
4+
import? '.just/gh-process.just'
5+
16
# run the code and see how it goes (default)
27
try:
38
cargo run -- ~/Downloads/Takeout ~/Documents/tmp
@@ -15,42 +20,3 @@ check:
1520
newdep crate_name:
1621
cargo add {{crate_name}}
1722
cargo doc
18-
19-
# get back to a clean start
20-
sync:
21-
git checkout main
22-
git pull
23-
cargo doc
24-
25-
release_branch := "main"
26-
27-
# error if not on a git branch
28-
on_a_branch:
29-
#!/bin/bash
30-
31-
# thanks to https://stackoverflow.com/a/12142066/2002471
32-
33-
if [[ $(git rev-parse --abbrev-ref HEAD) == "{{release_branch}}" ]]; then
34-
echo "You are on branch {{release_branch}} (the release branch) so you are not ready to start a PR."
35-
exit 100
36-
fi
37-
38-
# thanks to https://stackoverflow.com/a/7293026/2002471 for the perfect git incantation
39-
last_commit_message := `git log -1 --pretty=%B | grep .`
40-
pr_tmpfile := '/tmp/just-pr-body.txt'
41-
42-
# PR create v2.0
43-
pr: on_a_branch
44-
git stp
45-
git pushup
46-
#gh pr create --fill-verbose
47-
#gh pr create --title "{{last_commit_message}}" --body "{{last_commit_message}} (Automated in justfile.)"
48-
echo "Did: {{last_commit_message}}\n\n(Automated in `justfile`.)\n" > {{ pr_tmpfile }}
49-
gh pr create --title "{{last_commit_message}}" -F {{ pr_tmpfile }}
50-
rm {{ pr_tmpfile }}
51-
52-
# PR merge and return to main branch
53-
merge: on_a_branch
54-
gh pr merge -s
55-
git co {{release_branch}}
56-
git pull

0 commit comments

Comments
 (0)