@seangalie/precast 0.0.0-stage โ†’ 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/LICENSE +202 -0
  3. package/README.md +274 -2
  4. package/dist/bin.d.ts +2 -0
  5. package/dist/bin.js +3 -0
  6. package/dist/cli.d.ts +7 -0
  7. package/dist/cli.js +251 -0
  8. package/dist/collect.d.ts +17 -0
  9. package/dist/collect.js +143 -0
  10. package/dist/context.d.ts +38 -0
  11. package/dist/context.js +206 -0
  12. package/dist/errors.d.ts +8 -0
  13. package/dist/errors.js +8 -0
  14. package/dist/fnmatch.d.ts +9 -0
  15. package/dist/fnmatch.js +110 -0
  16. package/dist/generate.d.ts +23 -0
  17. package/dist/generate.js +76 -0
  18. package/dist/index.d.ts +7 -0
  19. package/dist/index.js +7 -0
  20. package/dist/output-path.d.ts +30 -0
  21. package/dist/output-path.js +84 -0
  22. package/dist/platforms.d.ts +22 -0
  23. package/dist/platforms.js +81 -0
  24. package/dist/profiles.d.ts +23 -0
  25. package/dist/profiles.js +79 -0
  26. package/dist/prompts.d.ts +30 -0
  27. package/dist/prompts.js +103 -0
  28. package/dist/style.d.ts +14 -0
  29. package/dist/style.js +34 -0
  30. package/dist/tiers.d.ts +23 -0
  31. package/dist/tiers.js +96 -0
  32. package/package.json +44 -4
  33. package/platforms/forgejo/files/.forgejo/CODEOWNERS.tmpl +2 -0
  34. package/platforms/forgejo/files/.forgejo/ISSUE_TEMPLATE/01_bug_report.yml.tmpl +83 -0
  35. package/platforms/forgejo/files/.forgejo/ISSUE_TEMPLATE/02_feature_request.yml.tmpl +57 -0
  36. package/platforms/forgejo/files/.forgejo/ISSUE_TEMPLATE/03_codebase_improvement.yml.tmpl +44 -0
  37. package/platforms/forgejo/files/.forgejo/ISSUE_TEMPLATE/04_support_question.yml.tmpl +47 -0
  38. package/platforms/forgejo/files/.forgejo/ISSUE_TEMPLATE/config.yml.tmpl +13 -0
  39. package/platforms/forgejo/files/.forgejo/PULL_REQUEST_TEMPLATE.md.tmpl +49 -0
  40. package/platforms/forgejo/files/.forgejo/SETUP.md.tmpl +65 -0
  41. package/platforms/forgejo/files/.forgejo/labels.yml.tmpl +99 -0
  42. package/platforms/forgejo/files/.forgejo/scripts/check-labels.sh.tmpl +91 -0
  43. package/platforms/forgejo/files/.forgejo/scripts/sync-labels.sh.tmpl +165 -0
  44. package/platforms/forgejo/files/.forgejo/workflows/labels.yml.tmpl +45 -0
  45. package/platforms/forgejo/files/.forgejo/workflows/lint.yml.tmpl +78 -0
  46. package/platforms/forgejo/files/.forgejo/workflows/pr-labels.yml.tmpl +51 -0
  47. package/platforms/forgejo/files/.forgejo/workflows/pre-commit.yml.tmpl +24 -0
  48. package/platforms/forgejo/files/.forgejo/workflows/release.yml.tmpl +130 -0
  49. package/platforms/forgejo/files/.forgejo/workflows/renovate.yml.tmpl +61 -0
  50. package/platforms/forgejo/files/.forgejo/workflows/stale.yml.tmpl +260 -0
  51. package/platforms/forgejo/files/renovate.json +36 -0
  52. package/platforms/forgejo/platform.json +41 -0
  53. package/platforms/github/files/.github/CODEOWNERS.tmpl +2 -0
  54. package/platforms/github/files/.github/ISSUE_TEMPLATE/01_bug_report.yml.tmpl +83 -0
  55. package/platforms/github/files/.github/ISSUE_TEMPLATE/02_feature_request.yml.tmpl +57 -0
  56. package/platforms/github/files/.github/ISSUE_TEMPLATE/03_codebase_improvement.yml.tmpl +44 -0
  57. package/platforms/github/files/.github/ISSUE_TEMPLATE/04_support_question.yml.tmpl +47 -0
  58. package/platforms/github/files/.github/ISSUE_TEMPLATE/config.yml.tmpl +16 -0
  59. package/platforms/github/files/.github/PULL_REQUEST_TEMPLATE.md.tmpl +49 -0
  60. package/platforms/github/files/.github/SETUP.md.tmpl +46 -0
  61. package/platforms/github/files/.github/dependabot.yml.tmpl +75 -0
  62. package/platforms/github/files/.github/labels.yml.tmpl +103 -0
  63. package/platforms/github/files/.github/release.yml.tmpl +47 -0
  64. package/platforms/github/files/.github/workflows/ci.yml.tmpl +55 -0
  65. package/platforms/github/files/.github/workflows/codeql.yml.tmpl +63 -0
  66. package/platforms/github/files/.github/workflows/labels.yml.tmpl +34 -0
  67. package/platforms/github/files/.github/workflows/lint-workflows.yml.tmpl +75 -0
  68. package/platforms/github/files/.github/workflows/lint.yml.tmpl +69 -0
  69. package/platforms/github/files/.github/workflows/lock.yml.tmpl +46 -0
  70. package/platforms/github/files/.github/workflows/pr-labels.yml.tmpl +26 -0
  71. package/platforms/github/files/.github/workflows/pre-commit.yml.tmpl +25 -0
  72. package/platforms/github/files/.github/workflows/release.yml.tmpl +101 -0
  73. package/platforms/github/files/.github/workflows/stale.yml.tmpl +57 -0
  74. package/platforms/github/platform.json +44 -0
  75. package/platforms/gitlab/files/.gitlab/CODEOWNERS.tmpl +2 -0
  76. package/platforms/gitlab/files/.gitlab/SETUP.md.tmpl +65 -0
  77. package/platforms/gitlab/files/.gitlab/issue_templates/01_bug_report.md +18 -0
  78. package/platforms/gitlab/files/.gitlab/issue_templates/02_feature_request.md +11 -0
  79. package/platforms/gitlab/files/.gitlab/issue_templates/03_codebase_improvement.md +11 -0
  80. package/platforms/gitlab/files/.gitlab/issue_templates/04_support_question.md +12 -0
  81. package/platforms/gitlab/files/.gitlab/labels.json +122 -0
  82. package/platforms/gitlab/files/.gitlab/merge_request_templates/Default.md +14 -0
  83. package/platforms/gitlab/files/.gitlab/scripts/project.py +159 -0
  84. package/platforms/gitlab/files/.gitlab-ci.yml.tmpl +56 -0
  85. package/platforms/gitlab/platform.json +38 -0
  86. package/template/.editorconfig.tmpl +54 -0
  87. package/template/.gitattributes +107 -0
  88. package/template/.gitignore.tmpl +244 -0
  89. package/template/.pre-commit-config.yaml.tmpl +55 -0
  90. package/template/.repo/check-secrets.py +40 -0
  91. package/template/.repo/ci-checks.sh +20 -0
  92. package/template/AGENTS.md.tmpl +78 -0
  93. package/template/CHANGELOG.md.tmpl +24 -0
  94. package/template/CLAUDE.md +1 -0
  95. package/template/LICENSE +202 -0
  96. package/template/README.md.tmpl +101 -0
  97. package/template/SETUP.md.tmpl +56 -0
  98. package/template/docs/CODE_OF_CONDUCT.md +85 -0
  99. package/template/docs/CONTRIBUTING.md.tmpl +59 -0
  100. package/template/docs/SECURITY.md.tmpl +26 -0
  101. package/template/docs/SUPPORT.md.tmpl +19 -0
  102. package/template/docs/logo.svg +84 -0
  103. package/template/docs/screenshot.png +0 -0
  104. package/tiers.json +10 -0
@@ -0,0 +1,65 @@
1
+ # Forgejo setup
2
+
3
+ Use this alongside the shared `SETUP.md` checklist.
4
+
5
+ @@TIERS slim@@
6
+ - [ ] Enable the repository units I need under Settings, such as Issues.
7
+ - [ ] Configure branch protection if the project needs it.
8
+
9
+ Generate with `--tier regular` or `--tier full` for issue templates, CI, and automation.
10
+ @@END_TIERS@@
11
+ @@TIERS regular@@
12
+ - [ ] Enable the repository units I need under Settings, including Issues and
13
+ Actions. Confirm a runner advertises the selected label from the workflow files.
14
+ The Pre-commit job runs in that label's job container, so its image must provide
15
+ Git, Bash, and Python 3.10+ with venv, plus access to the Python package index,
16
+ GitHub hook sources, and Go toolchain/module downloads. Hosted runners, such as
17
+ Codeberg's, may use their own labels instead of `ubuntu-latest`; generate with
18
+ `--runner LABEL` to match one.
19
+ @@END_TIERS@@
20
+ @@TIERS full@@
21
+ - [ ] Enable the repository units I need under Settings, including Issues, Actions,
22
+ and Releases. Confirm a runner advertises the selected label from the workflow files.
23
+ The Pre-commit job runs in that label's job container, so its image must provide
24
+ Git, Bash, and Python 3.10+ with venv, plus access to the Python package index,
25
+ GitHub hook sources, and Go toolchain/module downloads. Hosted runners, such as
26
+ Codeberg's, may use their own labels instead of `ubuntu-latest`; generate with
27
+ `--runner LABEL` to match one.
28
+ - [ ] Run **Actions โ†’ Sync labels โ†’ Run workflow** once after the first push. It
29
+ uses `.forgejo/labels.yml`; PR Labels needs these labels to exist. Alternatively,
30
+ run `.forgejo/scripts/sync-labels.sh` with `FORGEJO_API`, `FORGEJO_TOKEN`, `OWNER`,
31
+ and `REPO` supplied through the environment. Keep tokens out of commands, logs,
32
+ and Git. Review the script's header for its API URL format.
33
+ @@END_TIERS@@
34
+ @@TIERS regular full@@
35
+ - [ ] Review `.forgejo/CODEOWNERS`. Its paths are Go regular expressions: the
36
+ catch-all is `.*`. Organizations must name a team with write access.
37
+ - [ ] Extend `.forgejo/workflows/lint.yml` with real project build and test jobs.
38
+ @@END_TIERS@@
39
+ @@TIERS regular@@
40
+ Its existing jobs lint workflows, shell scripts, and EditorConfig.
41
+ @@END_TIERS@@
42
+ @@TIERS full@@
43
+ Its existing jobs lint workflows, shell scripts, EditorConfig, and label consistency.
44
+ @@END_TIERS@@
45
+ @@TIERS regular full@@
46
+ - [ ] Configure branch protection after checking the actual PR status contexts.
47
+ Contexts can include an event suffix; avoid requiring a push-only context on PRs.
48
+ @@END_TIERS@@
49
+ @@TIERS full@@
50
+ - [ ] To use Renovate, create a dedicated bot with repository access and supply
51
+ `RENOVATE_TOKEN` as an Actions secret. Review `.forgejo/workflows/renovate.yml`
52
+ and `renovate.json`. The bot needs suitable repository, issue, user, and organization
53
+ read scopes even for personal repositories; package access is separate if needed.
54
+ Confirm scopes against the installed Forgejo and Renovate versions.
55
+ - [ ] Review `.forgejo/workflows/stale.yml`: eligible items become stale after
56
+ 60 quiet days and close 14 days later. Review its exemptions before enabling it.
57
+ - [ ] Prepare a matching changelog section before pushing a `vX.Y.Z` tag. The
58
+ release workflow publishes notes, not build artifacts, and requires Releases enabled.
59
+ @@END_TIERS@@
60
+ @@TIERS regular full@@
61
+ - [ ] Set a real private security contact in `docs/SECURITY.md`.
62
+ @@END_TIERS@@
63
+
64
+ This overlay does not assume GitHub Discussions, Dependabot, CodeQL, private
65
+ advisory reporting, or the GitHub API. Generation did not apply any remote settings.
@@ -0,0 +1,99 @@
1
+ ---
2
+ # Applied by .forgejo/scripts/sync-labels.sh, which runs from the Template
3
+ # Bootstrap and the Sync labels workflows. Existing labels are updated in
4
+ # place; labels missing from this file are left alone.
5
+ #
6
+ # Issues and pull requests use different labels for the same kind of work:
7
+ # an issue reports a `bug` or asks for an `enhancement`; the pull request that
8
+ # answers it is a `bugfix` or a `new-feature`. The pull-request labels are the
9
+ # ones the PR Labels check accepts. The "Kind of change" group below must match
10
+ # REQUIRED_LABELS in .forgejo/workflows/pr-labels.yml exactly;
11
+ # .forgejo/scripts/check-labels.sh fails the Lint workflow if they drift.
12
+
13
+ # Kind of change. Every pull request needs at least one of these.
14
+ - name: "breaking-change"
15
+ color: e11d21
16
+ description: "Changes the API or breaks backward compatibility for users."
17
+ - name: "bugfix"
18
+ color: ee0701
19
+ description: "Resolves a defect for users or implementors."
20
+ - name: "new-feature"
21
+ color: 0e8a16
22
+ description: "Adds a new capability or option."
23
+ - name: "enhancement"
24
+ color: a2eeef
25
+ description: "Improves something that already exists, or asks for an improvement or a new capability."
26
+ - name: "documentation"
27
+ color: 0052cc
28
+ description: "Solely about the documentation of the project."
29
+ - name: "refactor"
30
+ color: 1d76db
31
+ description: "Simpler, clearer or more efficient code with no change in behavior."
32
+ - name: "performance"
33
+ color: 1d76db
34
+ description: "Makes the project faster or lighter with no change in behavior."
35
+ - name: "maintenance"
36
+ color: 2af79e
37
+ description: "Upkeep with no change in behavior: tooling, tests, housekeeping."
38
+ - name: "ci"
39
+ color: 1d76db
40
+ description: "Continuous integration and the workflows under .forgejo/."
41
+ - name: "dependencies"
42
+ color: 1d76db
43
+ description: "Updates project dependencies."
44
+
45
+ # Kind of issue.
46
+ - name: "bug"
47
+ color: d73a4a
48
+ description: "A reported defect: something is not working as intended."
49
+ - name: "security"
50
+ color: 9e1c23
51
+ description: "Addresses a vulnerability or security risk in this project."
52
+ - name: "question"
53
+ color: d876e3
54
+ description: "A request for support or further information about this project."
55
+
56
+ # Triage.
57
+ - name: "incomplete"
58
+ color: fef2c0
59
+ description: "Missing the information needed to act on it."
60
+ - name: "invalid"
61
+ color: e4e669
62
+ description: "Off-topic, spam, or otherwise does not apply to this project."
63
+ - name: "beginner-friendly"
64
+ color: 7057ff
65
+ description: "A good first issue for people new to this project."
66
+ - name: "help-wanted"
67
+ color: 008672
68
+ description: "Extra hands or expertise are needed to resolve this."
69
+
70
+ # Workflow state. The Stale workflow applies `stale` and skips anything
71
+ # carrying `no-stale` or `in-progress`.
72
+ - name: "in-progress"
73
+ color: 5319e7
74
+ description: "Someone is actively working on this."
75
+ - name: "stale"
76
+ color: ededed
77
+ description: "No activity for a while; closed soon unless that changes."
78
+ - name: "no-stale"
79
+ color: ededed
80
+ description: "Exempt from the Stale workflow."
81
+
82
+ # Priority. Scoped and exclusive: Forgejo shows these as priority/<level> and
83
+ # keeps at most one on an issue, so raising the priority replaces the old one.
84
+ - name: "priority/critical"
85
+ color: b60205
86
+ description: "Must be addressed as soon as possible."
87
+ exclusive: true
88
+ - name: "priority/high"
89
+ color: d93f0b
90
+ description: "Next in line once critical issues are resolved."
91
+ exclusive: true
92
+ - name: "priority/medium"
93
+ color: fbca04
94
+ description: "Worth doing; needs some attention."
95
+ exclusive: true
96
+ - name: "priority/low"
97
+ color: c2e0c6
98
+ description: "Nice to have, when time allows."
99
+ exclusive: true
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env bash
2
+ # Checks that the pull-request labels are the same everywhere they are listed.
3
+ # The Lint workflow runs it; so can a person, from the repository root:
4
+ # bash .forgejo/scripts/check-labels.sh
5
+ #
6
+ # REQUIRED_LABELS in .forgejo/workflows/pr-labels.yml is the list the PR Labels
7
+ # check enforces. The "Kind of change" group at the top of .forgejo/labels.yml
8
+ # must hold exactly the same labels, so a label added to or removed from either
9
+ # one alone fails here. The pull request template and docs/CONTRIBUTING.md name
10
+ # a few labels as examples, and each of those must be an accepted one.
11
+ #
12
+ # Exits non-zero, naming every mismatch, if anything disagrees.
13
+
14
+ set -euo pipefail
15
+
16
+ WORKFLOW=".forgejo/workflows/pr-labels.yml"
17
+ LABELS_FILE=".forgejo/labels.yml"
18
+
19
+ failures=0
20
+ fail() {
21
+ echo "::error::$*"
22
+ failures=$((failures + 1))
23
+ }
24
+
25
+ # The folded REQUIRED_LABELS block: every line indented deeper than the key.
26
+ required_set() {
27
+ awk '
28
+ match($0, /^[[:space:]]*REQUIRED_LABELS:/) {
29
+ indent = match($0, /[^[:space:]]/); grab = 1; next
30
+ }
31
+ grab && match($0, /[^[:space:]]/) > indent { print; next }
32
+ grab { exit }
33
+ ' "$WORKFLOW" | tr -s ' \t' '\n' | grep -v '^$' | sort -u
34
+ }
35
+
36
+ # The "Kind of change" group in labels.yml, up to the blank line ending it.
37
+ labels_yml_set() {
38
+ awk '
39
+ /^# Kind of change/ { grab = 1; next }
40
+ grab && /^$/ { exit }
41
+ grab
42
+ ' "$LABELS_FILE" | sed -n 's/^- name: "\(.*\)"$/\1/p' | sort -u
43
+ }
44
+
45
+ # The backticked lower-case words in the Markdown list item containing the
46
+ # marker, which leaves out names such as `REQUIRED_LABELS` and `PR Labels`.
47
+ # shellcheck disable=SC2016 # The backticks are Markdown, matched literally.
48
+ example_set() {
49
+ awk -v marker="$2" '
50
+ index($0, marker) { grab = 1; print; next }
51
+ grab && (/^- / || /^$/) { exit }
52
+ grab
53
+ ' "$1" | grep -oE '`[a-z][a-z-]*`' | tr -d '`' | sort -u
54
+ }
55
+
56
+ # Lines of $2 that are not in $1 (both sorted sets).
57
+ not_in() {
58
+ comm -13 <(printf '%s\n' "$1") <(printf '%s\n' "$2") | tr '\n' ' '
59
+ }
60
+
61
+ required="$(required_set)"
62
+ if [ -z "$required" ]; then
63
+ echo "::error::Could not read REQUIRED_LABELS from ${WORKFLOW}."
64
+ exit 1
65
+ fi
66
+
67
+ labels="$(labels_yml_set)"
68
+ extra="$(not_in "$required" "$labels")"
69
+ missing="$(not_in "$labels" "$required")"
70
+ [ -z "$extra" ] || fail "${LABELS_FILE} lists labels under \"Kind of change\" that REQUIRED_LABELS does not accept: ${extra}"
71
+ [ -z "$missing" ] || fail "${LABELS_FILE} is missing labels REQUIRED_LABELS accepts: ${missing}"
72
+
73
+ check_examples() {
74
+ local file="$1" found unknown
75
+ found="$(example_set "$file" "$2")"
76
+ if [ -z "$found" ]; then
77
+ fail "${file} no longer names any example labels; update this check if that was deliberate."
78
+ return
79
+ fi
80
+ unknown="$(not_in "$required" "$found")"
81
+ [ -z "$unknown" ] || fail "${file} names labels REQUIRED_LABELS does not accept: ${unknown}"
82
+ }
83
+
84
+ check_examples .forgejo/PULL_REQUEST_TEMPLATE.md "saying what kind of change it is"
85
+ check_examples docs/CONTRIBUTING.md "**A label is required.**"
86
+
87
+ if [ "$failures" -gt 0 ]; then
88
+ echo "${failures} label check(s) failed. REQUIRED_LABELS is: $(printf '%s' "$required" | tr '\n' ' ')"
89
+ exit 1
90
+ fi
91
+ echo "Pull-request labels agree: $(printf '%s' "$required" | tr '\n' ' ')"
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env bash
2
+ # Applies .forgejo/labels.yml to the repository through the Forgejo API.
3
+ #
4
+ # Forgejo has no label-sync integration and the GitHub actions that do this
5
+ # (EndBug/label-sync and friends) speak GitHub's API shape, so this is done
6
+ # directly against /api/v1.
7
+ #
8
+ # Labels that already exist are updated in place, keeping their ID and so the
9
+ # issues already carrying them. Labels absent from labels.yml are left alone
10
+ # unless DELETE_OTHERS=true.
11
+ #
12
+ # A label may set `exclusive: true`. Forgejo then treats labels sharing its
13
+ # scope (the part before the last "/", as in priority/high) as mutually
14
+ # exclusive: adding one to an issue removes the others.
15
+ #
16
+ # Exits non-zero if any label could not be created, updated or deleted, so a
17
+ # partial sync does not show up as a green run.
18
+ #
19
+ # Required environment:
20
+ # FORGEJO_API base API URL, e.g. https://git.example.org/api/v1
21
+ # FORGEJO_TOKEN token with write access to the repository
22
+ # OWNER, REPO repository coordinates
23
+ # Optional:
24
+ # LABELS_FILE defaults to .forgejo/labels.yml
25
+ # DELETE_OTHERS "true" removes labels not present in the file
26
+ # PAGE_LIMIT page size when listing labels; defaults to 50
27
+ # MAX_PAGES backstop against a server that never returns an empty page
28
+
29
+ set -euo pipefail
30
+
31
+ LABELS_FILE="${LABELS_FILE:-.forgejo/labels.yml}"
32
+ DELETE_OTHERS="${DELETE_OTHERS:-false}"
33
+ PAGE_LIMIT="${PAGE_LIMIT:-50}"
34
+ MAX_PAGES="${MAX_PAGES:-100}"
35
+
36
+ : "${FORGEJO_API:?FORGEJO_API is required}"
37
+ : "${FORGEJO_TOKEN:?FORGEJO_TOKEN is required}"
38
+ : "${OWNER:?OWNER is required}"
39
+ : "${REPO:?REPO is required}"
40
+
41
+ api() {
42
+ # api METHOD PATH [JSON_BODY]
43
+ local method="$1" path="$2" body="${3:-}"
44
+ local args=(-sS -X "$method"
45
+ -H "Authorization: token ${FORGEJO_TOKEN}"
46
+ -H "Accept: application/json"
47
+ -H "Content-Type: application/json"
48
+ -w '\n%{http_code}')
49
+ [ -n "$body" ] && args+=(-d "$body")
50
+ curl "${args[@]}" "${FORGEJO_API}${path}"
51
+ }
52
+
53
+ # Splits the `body\nstatus` that api() returns.
54
+ api_ok() {
55
+ local response status
56
+ response="$(api "$@")" || return 1
57
+ status="${response##*$'\n'}"
58
+ RESPONSE_BODY="${response%$'\n'*}"
59
+ case "$status" in
60
+ 2*) return 0 ;;
61
+ *) echo " API ${1} ${2} failed with HTTP ${status}: ${RESPONSE_BODY}" >&2; return 1 ;;
62
+ esac
63
+ }
64
+
65
+ # labels.yml is a flat list of `- name: / color: / description: / exclusive:`
66
+ # entries. Parsed here rather than with yq, which the runner image does not
67
+ # ship.
68
+ parse_labels() {
69
+ awk '
70
+ function strip(v) {
71
+ sub(/^[[:space:]]*/, "", v); sub(/[[:space:]]*$/, "", v)
72
+ if (v ~ /^".*"$/) { v = substr(v, 2, length(v) - 2) }
73
+ else if (v ~ /^'"'"'.*'"'"'$/) { v = substr(v, 2, length(v) - 2) }
74
+ return v
75
+ }
76
+ function flush() {
77
+ if (name != "") { printf "%s\t%s\t%s\t%s\n", name, color, desc, (excl == "true" ? "true" : "false") }
78
+ name = ""; color = ""; desc = ""; excl = ""
79
+ }
80
+ /^[[:space:]]*#/ { next }
81
+ /^[[:space:]]*-[[:space:]]*name:/ {
82
+ flush(); sub(/^[[:space:]]*-[[:space:]]*name:/, ""); name = strip($0); next
83
+ }
84
+ /^[[:space:]]*color:/ { sub(/^[[:space:]]*color:/, ""); color = strip($0); next }
85
+ /^[[:space:]]*description:/ { sub(/^[[:space:]]*description:/, ""); desc = strip($0); next }
86
+ /^[[:space:]]*exclusive:/ { sub(/^[[:space:]]*exclusive:/, ""); excl = strip($0); next }
87
+ END { flush() }
88
+ ' "$LABELS_FILE"
89
+ }
90
+
91
+ [ -f "$LABELS_FILE" ] || { echo "::error::${LABELS_FILE} not found."; exit 1; }
92
+
93
+ echo "Syncing labels from ${LABELS_FILE} into ${OWNER}/${REPO}"
94
+
95
+ # Existing labels, as a name -> id map.
96
+ #
97
+ # Pages until the server returns an empty page rather than until it returns a
98
+ # short one. Forgejo clamps `limit` to the instance's api.MAX_RESPONSE_ITEMS,
99
+ # so a page shorter than PAGE_LIMIT does not mean the last page.
100
+ existing="[]"
101
+ page=1
102
+ while [ "$page" -le "$MAX_PAGES" ]; do
103
+ api_ok GET "/repos/${OWNER}/${REPO}/labels?page=${page}&limit=${PAGE_LIMIT}" || exit 1
104
+ chunk="$RESPONSE_BODY"
105
+ count="$(printf '%s' "$chunk" | jq 'length')"
106
+ [ "$count" -eq 0 ] && break
107
+ existing="$(jq -s '.[0] + .[1]' <(printf '%s' "$existing") <(printf '%s' "$chunk"))"
108
+ page=$((page + 1))
109
+ done
110
+ if [ "$page" -gt "$MAX_PAGES" ]; then
111
+ # Carrying on would create duplicates of any label on the unread pages.
112
+ echo "::error::Stopped listing labels after ${MAX_PAGES} pages; refusing to sync from a partial list."
113
+ exit 1
114
+ fi
115
+
116
+ created=0; updated=0; deleted=0; failed=0; wanted_names=()
117
+
118
+ while IFS=$'\t' read -r name color desc exclusive; do
119
+ [ -n "$name" ] || continue
120
+ wanted_names+=("$name")
121
+ color="#${color#\#}" # Forgejo wants the leading # on label colors
122
+
123
+ payload="$(jq -nc --arg n "$name" --arg c "$color" --arg d "$desc" \
124
+ --argjson e "$exclusive" \
125
+ '{name: $n, color: $c, description: $d, exclusive: $e}')"
126
+
127
+ id="$(printf '%s' "$existing" | jq -r --arg n "$name" \
128
+ 'map(select(.name == $n)) | .[0].id // empty')"
129
+
130
+ if [ -n "$id" ]; then
131
+ if api_ok PATCH "/repos/${OWNER}/${REPO}/labels/${id}" "$payload"; then
132
+ updated=$((updated + 1))
133
+ else
134
+ failed=$((failed + 1))
135
+ fi
136
+ else
137
+ if api_ok POST "/repos/${OWNER}/${REPO}/labels" "$payload"; then
138
+ created=$((created + 1))
139
+ echo " created ${name}"
140
+ else
141
+ failed=$((failed + 1))
142
+ fi
143
+ fi
144
+ done < <(parse_labels)
145
+
146
+ if [ "$DELETE_OTHERS" = "true" ]; then
147
+ wanted_json="$(printf '%s\n' "${wanted_names[@]}" | jq -R . | jq -sc .)"
148
+ while read -r id name; do
149
+ [ -n "$id" ] || continue
150
+ if api_ok DELETE "/repos/${OWNER}/${REPO}/labels/${id}"; then
151
+ deleted=$((deleted + 1))
152
+ echo " deleted ${name}"
153
+ else
154
+ failed=$((failed + 1))
155
+ fi
156
+ done < <(printf '%s' "$existing" | jq -r --argjson want "$wanted_json" \
157
+ '.[] | select(.name as $n | $want | index($n) | not) | "\(.id) \(.name)"')
158
+ fi
159
+
160
+ echo "Labels synced: ${created} created, ${updated} updated, ${deleted} deleted, ${failed} failed."
161
+
162
+ if [ "$failed" -gt 0 ]; then
163
+ echo "::error::${failed} label operation(s) failed; see the messages above."
164
+ exit 1
165
+ fi
@@ -0,0 +1,45 @@
1
+ ---
2
+ # Applies .forgejo/labels.yml to the repository.
3
+ #
4
+ # The GitHub label-sync actions all speak GitHub's API, so this calls Forgejo's
5
+ # /api/v1 directly through .forgejo/scripts/sync-labels.sh instead.
6
+
7
+ name: Sync labels
8
+
9
+ on:
10
+ push:
11
+ branches:
12
+ - @@DEFAULT_BRANCH_YAML@@
13
+ paths:
14
+ - .forgejo/labels.yml
15
+ - .forgejo/scripts/sync-labels.sh
16
+ workflow_dispatch:
17
+
18
+ jobs:
19
+ labels:
20
+ name: โ™ป๏ธ Sync labels
21
+ runs-on: @@RUNNER_YAML@@
22
+ env:
23
+ FORGEJO_API: ${{ github.api_url }}
24
+ FORGEJO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25
+ REPO_FULL: ${{ github.repository }}
26
+ # Set to true to remove any label that is not defined in labels.yml.
27
+ # Left off by default so Forgejo's stock labels survive the first sync.
28
+ DELETE_OTHERS: "false"
29
+ steps:
30
+ - name: โคต๏ธ Check out the repository
31
+ uses: https://data.forgejo.org/actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
32
+
33
+ - name: ๐Ÿงฐ Make sure jq is available
34
+ run: |
35
+ set -euo pipefail
36
+ command -v jq >/dev/null 2>&1 || {
37
+ apt-get update -qq && apt-get install -y -qq jq
38
+ }
39
+
40
+ - name: ๐Ÿš€ Apply the labels
41
+ run: |
42
+ set -euo pipefail
43
+ export OWNER="${REPO_FULL%%/*}"
44
+ export REPO="${REPO_FULL##*/}"
45
+ bash .forgejo/scripts/sync-labels.sh
@@ -0,0 +1,78 @@
1
+ ---
2
+ # Lints what the template itself ships: the workflows, the shell they run,
3
+ # the standalone shell scripts, and the .editorconfig rules every text file is
4
+ # expected to follow. Add the project's own linters and tests here, or in a
5
+ # workflow of their own.
6
+ #
7
+ # Each tool runs from its official image, pinned by version and immutable
8
+ @@TIERS regular@@
9
+ # digest, so the runner needs nothing installed.
10
+ @@END_TIERS@@
11
+ @@TIERS full@@
12
+ # digest the same way Renovate is, so the runner needs nothing installed and
13
+ # Renovate can keep them current.
14
+ @@END_TIERS@@
15
+ #
16
+ # Tests that need another image belong in a `docker://` step like these, not
17
+ # on a different runner label: plain images such as debian-* have no node, so
18
+ # the JavaScript checkout action fails before the first step. A `container:`
19
+ # does not help either, since the steps then run inside it.
20
+
21
+ name: Lint
22
+
23
+ on:
24
+ push:
25
+ branches:
26
+ - @@DEFAULT_BRANCH_YAML@@
27
+ pull_request:
28
+ workflow_dispatch:
29
+
30
+ jobs:
31
+ lint:
32
+ name: ๐Ÿ” Lint
33
+ runs-on: @@RUNNER_YAML@@
34
+ steps:
35
+ - name: โคต๏ธ Check out the repository
36
+ uses: https://data.forgejo.org/actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
37
+ with:
38
+ persist-credentials: false
39
+
40
+ # actionlint also runs shellcheck over every `run:` block; the image
41
+ # bundles it. It only discovers .github/workflows by itself, hence the
42
+ # explicit file discovery below. The -ignore covers the
43
+ # full-URL `uses:` that Forgejo needs to reach actions on another host,
44
+ # which actionlint does not know about.
45
+ - name: ๐ŸŽฌ actionlint
46
+ uses: docker://rhysd/actionlint:1.7.12@sha256:b1934ee5f1c509618f2508e6eb47ee0d3520686341fec936f3b79331f9315667
47
+ with:
48
+ entrypoint: /bin/sh
49
+ args: >-
50
+ -c 'find .forgejo/workflows -maxdepth 1 -type f
51
+ \( -name "*.yml" -o -name "*.yaml" \)
52
+ -exec actionlint -color
53
+ -ignore "specifying action \"https://[^\"]+\" in invalid format" {} +'
54
+
55
+ # actionlint only reaches shell inside workflows, so standalone scripts
56
+ # get their own pass. Any *.sh or *.bash outside .git is picked up; a
57
+ # script without either extension needs adding here. xargs -r skips the
58
+ # run when there are none, and fails the step if shellcheck does.
59
+ - name: ๐Ÿš shellcheck
60
+ uses: docker://koalaman/shellcheck-alpine:v0.11.0@sha256:9955be09ea7f0dbf7ae942ac1f2094355bb30d96fffba0ec09f5432207544002
61
+ with:
62
+ entrypoint: /bin/sh
63
+ args: >-
64
+ -c 'find . -path ./.git -prune -o -type f
65
+ \( -name "*.sh" -o -name "*.bash" \) -print0
66
+ | xargs -0 -r shellcheck'
67
+
68
+ # Checks every file tracked by git against .editorconfig.
69
+ - name: ๐Ÿ“ editorconfig-checker
70
+ uses: docker://mstruebing/editorconfig-checker:4.0.2@sha256:2ba6232bfa0058f72f5f7d7816711590aa764afab1542af30b3ecb4553587918
71
+ @@TIERS full@@
72
+
73
+ # REQUIRED_LABELS in pr-labels.yml and the "Kind of change" group in
74
+ # labels.yml must list the same labels; the script explains the rest.
75
+ # It needs only bash and coreutils, so it runs on the runner itself.
76
+ - name: ๐Ÿท Check the pull-request labels
77
+ run: bash .forgejo/scripts/check-labels.sh
78
+ @@END_TIERS@@
@@ -0,0 +1,51 @@
1
+ ---
2
+ # Requires every pull request to carry at least one of the labels that drive
3
+ # the changelog and the release notes.
4
+ #
5
+ # mheap/github-action-required-labels talks to GitHub's API, so this reads the
6
+ # labels straight off the pull_request event payload instead -- no API call and
7
+ # no checkout needed.
8
+ #
9
+ # REQUIRED_LABELS is the one list of accepted labels. The pull request template
10
+ # and docs/CONTRIBUTING.md point here rather than repeating it. The "Kind of
11
+ # change" group in .forgejo/labels.yml must list exactly the same labels, which
12
+ # .forgejo/scripts/check-labels.sh enforces in the Lint workflow.
13
+
14
+ name: PR Labels
15
+
16
+ on:
17
+ pull_request:
18
+ types: [opened, reopened, labeled, unlabeled, synchronize]
19
+
20
+ jobs:
21
+ pr_labels:
22
+ name: ๐Ÿญ Verify
23
+ runs-on: @@RUNNER_YAML@@
24
+ env:
25
+ REQUIRED_LABELS: >-
26
+ breaking-change bugfix new-feature enhancement documentation refactor
27
+ performance maintenance ci dependencies
28
+ PR_LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
29
+ steps:
30
+ - name: ๐Ÿท Verify the pull request has a valid label
31
+ run: |
32
+ set -euo pipefail
33
+
34
+ command -v jq >/dev/null 2>&1 || {
35
+ apt-get update -qq && apt-get install -y -qq jq
36
+ }
37
+
38
+ mapfile -t present < <(printf '%s' "$PR_LABELS" | jq -r '.[]?')
39
+
40
+ for label in "${present[@]}"; do
41
+ for required in $REQUIRED_LABELS; do
42
+ if [ "$label" = "$required" ]; then
43
+ echo "โœ… Found the required label: ${label}"
44
+ exit 0
45
+ fi
46
+ done
47
+ done
48
+
49
+ echo "::error::This pull request needs at least one of these labels: ${REQUIRED_LABELS}"
50
+ echo "Labels currently on this pull request: ${present[*]:-(none)}"
51
+ exit 1
@@ -0,0 +1,24 @@
1
+ name: Pre-commit
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - @@DEFAULT_BRANCH_YAML@@
7
+ pull_request:
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ checks:
12
+ runs-on: @@RUNNER_YAML@@
13
+ steps:
14
+ - name: Check out the repository
15
+ uses: https://data.forgejo.org/actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
16
+ with:
17
+ persist-credentials: false
18
+ # Runs in the job container, whose image must provide Git, Bash, and
19
+ # Python 3.10+ with venv. See .forgejo/SETUP.md.
20
+ - name: Run pre-commit checks
21
+ env:
22
+ # The digest-pinned Lint job owns these checks in CI. Local hooks run all.
23
+ SKIP: shellcheck,editorconfig-checker,actionlint
24
+ run: bash .repo/ci-checks.sh