|
1 | 1 | # project justfile |
2 | 2 |
|
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: |
4 | 13 | just --list |
5 | 14 | @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