Repository navigation
ci: Adopt atelier-store's CI, release and lint setup #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #!/usr/bin/env bash | ||
| # Keep local hook activation aligned with the distributed hook baseline. | ||
| # Git only runs this once core.hooksPath already points at .github/hooks, so | ||
| # it repairs the setting and permissions after that; it can't bootstrap a | ||
| # fresh clone. The one-time setup is in README.md: git config core.hooksPath .github/hooks | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || exit 0 | ||
| [[ -n "$REPO_ROOT" ]] || exit 0 | ||
|
|
||
| EXPECTED_HOOKS_PATH=".github/hooks" | ||
| CURRENT_HOOKS_PATH="$(git config --get core.hooksPath || true)" | ||
| NORMALIZED_HOOKS_PATH="${CURRENT_HOOKS_PATH#./}" | ||
|
|
||
| if [[ "$NORMALIZED_HOOKS_PATH" != "$EXPECTED_HOOKS_PATH" ]]; then | ||
| git config core.hooksPath "$EXPECTED_HOOKS_PATH" | ||
| fi | ||
|
|
||
| for hook in pre-commit pre-push post-checkout; do | ||
| hook_path="$REPO_ROOT/.github/hooks/$hook" | ||
| if [[ -f "$hook_path" ]] && [[ ! -x "$hook_path" ]]; then | ||
| chmod +x "$hook_path" | ||
| fi | ||
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #!/usr/bin/env bash | ||
| # Pre-commit gate: runs markdownlint-cli2 on staged .md files, with the same | ||
| # .markdownlint-cli2.jsonc config as CI. | ||
| # Blocks the commit if any markdownlint violations are found. | ||
| # Degrades gracefully if markdownlint-cli2 is not available. | ||
| set -uo pipefail | ||
|
|
||
| ROOT="$(git rev-parse --show-toplevel)" | ||
| cd "$ROOT" || exit 1 | ||
|
|
||
| RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; RESET='\033[0m' | ||
|
|
||
| # ββ Collect staged .md files βββββββββββββββββββββββββββββββββββββββββββββββ | ||
| STAGED_MD=$(git diff --cached --name-only --diff-filter=ACM | grep '\.md$' || true) | ||
|
|
||
| if [[ -z "$STAGED_MD" ]]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo -e "${CYAN}βββ Pre-Commit Markdownlint Gate ββββββββββββββββββββββββββββββββββ${RESET}" | ||
|
|
||
| # ββ Probe for markdownlint binary ββββββββββββββββββββββββββββββββββββββββββ | ||
| MARKDOWNLINT_BIN="" | ||
|
|
||
| # Only markdownlint-cli2 reads .markdownlint-cli2.jsonc, the config CI uses. | ||
| if [[ -x "$ROOT/node_modules/.bin/markdownlint-cli2" ]]; then | ||
| MARKDOWNLINT_BIN="$ROOT/node_modules/.bin/markdownlint-cli2" | ||
| elif command -v markdownlint-cli2 &>/dev/null; then | ||
| MARKDOWNLINT_BIN="markdownlint-cli2" | ||
| fi | ||
|
|
||
| if [[ -z "$MARKDOWNLINT_BIN" ]]; then | ||
| echo -e "${YELLOW}β οΈ markdownlint-cli2 not found β skipping markdown lint check.${RESET}" | ||
| echo -e " To enable: ${CYAN}npm install -g markdownlint-cli2${RESET}" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # ββ Run markdownlint on staged files ββββββββββββββββββββββββββββββββββββββ | ||
| echo -e " Linting staged .md files with: ${CYAN}$(basename "$MARKDOWNLINT_BIN")${RESET}" | ||
|
|
||
| # Build array of files and run linter | ||
| mapfile -t MD_FILES <<< "$STAGED_MD" | ||
|
|
||
| if "$MARKDOWNLINT_BIN" "${MD_FILES[@]}" 2>&1; then | ||
| echo -e "${GREEN}β All staged .md files passed markdownlint.${RESET}" | ||
| exit 0 | ||
| else | ||
| echo -e "" | ||
| echo -e "${RED}β Markdownlint violations found in staged files above.${RESET}" | ||
| echo -e " Fix the violations and re-stage the files before committing." | ||
| echo -e " To skip in an emergency: ${YELLOW}git commit --no-verify${RESET}" | ||
| exit 1 | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #!/usr/bin/env bash | ||
| # Pre-push gate: branch naming, then scripts/gate.sh (lint, build and tests) | ||
| set -euo pipefail | ||
|
|
||
| ROOT="$(git rev-parse --show-toplevel)" | ||
| cd "$ROOT" | ||
|
|
||
| RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; RESET='\033[0m' | ||
|
|
||
| echo -e "${CYAN}βββ Pre-Push Gate βββββββββββββββββββββββββββββββββββββββββββββββ${RESET}" | ||
|
|
||
| # Read push refs from stdin (provided by git when run as a hook). | ||
| PUSH_REFS="$(cat || true)" | ||
|
|
||
| is_protected_branch() { | ||
| [[ "$1" == "main" || "$1" == "preview" || "$1" == "dev" ]] | ||
| } | ||
|
|
||
| check_branch_name() { | ||
| local branch="$1" | ||
|
|
||
| if is_protected_branch "$branch"; then | ||
| echo -e "${RED}β Direct pushes to '${branch}' are not allowed.${RESET}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! [[ "$branch" =~ ^(squad|sprint|feature|hotfix)/[0-9]+-[a-z0-9]+(-[a-z0-9]+)*$ ]] && ! [[ "$branch" =~ ^chore/[a-z0-9]+(-[a-z0-9]+)*$ ]]; then | ||
| echo -e "${RED}β Branch name '${branch}' does not match naming convention.${RESET}" | ||
| echo -e " Expected: ${YELLOW}squad/{issue}-{slug}${RESET}, ${YELLOW}sprint/{n}-{slug}${RESET}, ${YELLOW}feature/{issue}-{slug}${RESET}, ${YELLOW}hotfix/{issue}-{slug}${RESET}, or ${YELLOW}chore/{kebab-slug}${RESET}" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| if [[ -n "$PUSH_REFS" ]]; then | ||
| # Gate the refs being pushed, not the checked-out branch: pushing another | ||
| # branch or deleting one from a main checkout is not a push to main. | ||
| # Classify by remote ref: `git push origin v1.0.0:main` has a tag as its | ||
| # local ref but still updates main. | ||
| UPDATES_BRANCH=false | ||
| while read -r _local_ref local_sha remote_ref _remote_sha; do | ||
| [[ "$remote_ref" == refs/heads/* ]] || continue | ||
| branch="${remote_ref#refs/heads/}" | ||
|
|
||
| if [[ "$local_sha" =~ ^0+$ ]]; then | ||
| if is_protected_branch "$branch"; then | ||
| echo -e "${RED}β Deleting '${branch}' is not allowed.${RESET}" | ||
| exit 1 | ||
| fi | ||
| continue | ||
| fi | ||
|
|
||
| check_branch_name "$branch" | ||
|
|
||
| # The gate runs against the working tree, so it only vouches for the | ||
| # commit that is checked out. Refuse a push of anything else (another | ||
| # branch, or a tag pushed to a branch) rather than gate the wrong code. | ||
| pushed_commit="$(git rev-parse --verify --quiet "${local_sha}^{commit}" || echo "$local_sha")" | ||
| if [[ "$pushed_commit" != "$(git rev-parse HEAD)" ]]; then | ||
| echo -e "${RED}β '${branch}' is not the checked-out commit, so the gate can't test it.${RESET}" | ||
| echo -e " Check it out first: ${YELLOW}git switch ${branch}${RESET}, then push again." | ||
| exit 1 | ||
| fi | ||
| UPDATES_BRANCH=true | ||
| done <<< "$PUSH_REFS" | ||
|
|
||
| if [[ "$UPDATES_BRANCH" == false ]]; then | ||
| echo -e "${GREEN}β No branch updates β skipping the gate.${RESET}" | ||
| exit 0 | ||
| fi | ||
| else | ||
| # Run by hand: there are no refs on stdin, so gate the checked-out branch. | ||
| check_branch_name "$(git symbolic-ref --short HEAD 2>/dev/null || echo "")" | ||
| fi | ||
|
|
||
| # Every pushed branch is the checked-out commit (checked above). The gate | ||
| # tests the working tree, so it must match that commit exactly: uncommitted | ||
| # or untracked files (an untracked .cs file still compiles) could pass the | ||
| # gate for code that isn't in the push. Ignored files don't count. | ||
| if [[ -n "$(git status --porcelain --untracked-files=all)" ]]; then | ||
| echo -e "${RED}β The working tree has uncommitted or untracked changes, so the gate can't vouch for the pushed commit.${RESET}" | ||
| echo -e " Commit them, or set them aside with ${YELLOW}git stash --include-untracked${RESET}, then push again." | ||
| git status --short | head -n 20 | ||
| exit 1 | ||
| fi | ||
| "$ROOT/scripts/gate.sh" | ||
|
|
||
| echo -e "\n${GREEN}βββ All gates passed β pushing β ββββββββββββββββββββββββββββββββββ${RESET}\n" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.