Skip to content

Commit

Permalink
fix: properly format files and re-run formatters on the repo (#112)
Browse files Browse the repository at this point in the history
Runs formatters on the repository as they were meant to be configured as
well adds `linters` Github Action group that ensures that formatters
were ran as well as code/doc generators.

Enables tabs instead of spaces across the entire repository because they
use less space and any modern editor should be configured to display
them to their liking. The only exception is YAML which has to be spaces.
We output `2` for the least amount as well as it being my preference
(again, configure your editor if you haven't already, if you don't like
2).
  • Loading branch information
jaredallard authored Jul 12, 2024
1 parent d89c704 commit 5daa92d
Show file tree
Hide file tree
Showing 45 changed files with 418 additions and 389 deletions.
12 changes: 4 additions & 8 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true

[*.go,Makefile]
max_line_length = 72
indent_style = tab

[*.{bash,rb,sh,slim,yml,yaml}]
# yaml is forced to use spaces :/
[*.{yml,yaml}]
indent_style = space
indent_size = 2

## <<Stencil::Block(editorconfig)>>

## <</Stencil::Block>>
3 changes: 2 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
-->

<!-- A short description of what your PR does and what it solves. -->
## What this PR does / why we need it

## What this PR does / why we need it

<!-- Notes that may be helpful for anyone reviewing this PR -->

## Notes for your reviewers
12 changes: 6 additions & 6 deletions .github/scripts/fury-upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ file_ext="${1##*.}"

is_allowed=false
for ext in "${allowed_exts[@]}"; do
if [[ "$ext" == "$file_ext" ]]; then
is_allowed=true
break
fi
if [[ "$ext" == "$file_ext" ]]; then
is_allowed=true
break
fi
done

if [[ "$is_allowed" == "false" ]]; then
exit 0
exit 0
fi

cd dist
echo "uploading $1"
status="$(curl -s -q -o /dev/null -w "%{http_code}" -F package="@$1" "https://${FURY_PUSH_TOKEN}@push.fury.io/rgst-io/")"
echo "got: $status"
if [[ "$status" == "200" ]] || [[ "$status" == "409" ]]; then
exit 0
exit 0
fi

# Otherwise, exit with an error
Expand Down
26 changes: 13 additions & 13 deletions .github/scripts/get-next-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ BUILD_RC=${BUILD_RC:=false}
# As a special case, if the first argument is --rc, the next version
# will be a release candidate version.
if [[ "${1:-}" == "--rc" ]]; then
BUILD_RC=true
BUILD_RC=true
fi

if [[ -n "$VERSION_OVERRIDE" ]]; then
echo "Overriding next version with: $VERSION_OVERRIDE" >&2
echo "$VERSION_OVERRIDE"
exit 0
echo "Overriding next version with: $VERSION_OVERRIDE" >&2
echo "$VERSION_OVERRIDE"
exit 0
fi

# Determine the next version as reported by the next-version command.
Expand All @@ -32,15 +32,15 @@ echo "Next release version: $next_version" >&2
# If the build is a release candidate, determine the last release
# candidate version and increment the release candidate number.
if [[ "$BUILD_RC" == "true" ]]; then
last_rc_version=$(git tag -l --sort=-v:refname | grep -- "$next_version" | grep -- "-rc." | head -n 1 || true)
if [[ -z "$last_rc_version" ]]; then
next_version="${next_version}-rc.1"
else
echo "Last release candidate version: $last_rc_version" >&2
last_rc_version_number=${last_rc_version##*-rc.}
next_rc_version_number=$((last_rc_version_number + 1))
next_version="${next_version}-rc.${next_rc_version_number}"
fi
last_rc_version=$(git tag -l --sort=-v:refname | grep -- "$next_version" | grep -- "-rc." | head -n 1 || true)
if [[ -z "$last_rc_version" ]]; then
next_version="${next_version}-rc.1"
else
echo "Last release candidate version: $last_rc_version" >&2
last_rc_version_number=${last_rc_version##*-rc.}
next_rc_version_number=$((last_rc_version_number + 1))
next_version="${next_version}-rc.${next_rc_version_number}"
fi
fi

echo "Next version: $next_version" >&2
Expand Down
3 changes: 1 addition & 2 deletions .github/settings.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Documentation can be found at:
# https://github.com/repository-settings/app/blob/master/docs/configuration.md
_extends: jaredallard/jaredallard:settings.yml

## <<Stencil::Block(custom)>>

## <</Stencil::Block>>
## <</Stencil::Block>>
67 changes: 67 additions & 0 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: linters
on:
push:
branches:
- main
pull_request:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
check-generated-files-and-fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2
with:
experimental: true
env:
GH_TOKEN: ${{ github.token }}
- name: Get Go directories
id: go
run: |
echo "cache_dir=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
echo "mod_cache_dir=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v4
with:
path: ${{ steps.go.outputs.cache_dir }}
key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}
- uses: actions/cache@v4
with:
path: ${{ steps.go.outputs.mod_cache_dir }}
key: ${{ runner.os }}-go-mod-cache-${{ hashFiles('**/go.sum') }}
- name: Setup prettier
run: bun install
- run: mise run generate
- run: mise run fmt
- name: Check for changes
run: |-
git diff --exit-code HEAD || \
( echo \
&& echo "Formatting issues or stale documentation found. Please run the 'generate' and 'fmt' tasks." \
&& exit 1)
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2
with:
experimental: true
env:
GH_TOKEN: ${{ github.token }}
- name: Retrieve golangci-lint version
run: |
echo "version=$(mise current golangci-lint)" >> "$GITHUB_OUTPUT"
id: golangci_lint
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v${{ steps.golangci_lint.outputs.version }}
args: --timeout=30m
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ permissions:
issues: write

concurrency:
group: stencil-release-${{ github.head_ref }}
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
- uses: actions/cache@v4
with:
path: ${{ steps.go.outputs.cache_dir }}
key: ${{ runner.os }}-go-build-cache
key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}
- uses: actions/cache@v4
with:
path: ${{ steps.go.outputs.mod_cache_dir }}
Expand Down
35 changes: 14 additions & 21 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ permissions:
contents: read

concurrency:
group: stencil-build-${{ github.head_ref }}
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
Expand All @@ -23,6 +23,19 @@ jobs:
experimental: true
env:
GH_TOKEN: ${{ github.token }}
- name: Get Go directories
id: go
run: |
echo "cache_dir=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
echo "mod_cache_dir=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v4
with:
path: ${{ steps.go.outputs.cache_dir }}
key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}
- uses: actions/cache@v4
with:
path: ${{ steps.go.outputs.mod_cache_dir }}
key: ${{ runner.os }}-go-mod-cache-${{ hashFiles('go.sum') }}
- name: Download dependencies
run: go mod download
- name: Run go test
Expand All @@ -34,23 +47,3 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./cover.out
fail_ci_if_error: true

golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2
with:
experimental: true
env:
GH_TOKEN: ${{ github.token }}
- name: Retrieve golangci-lint version
run: |
echo "version=$(mise current golangci-lint)" >> "$GITHUB_OUTPUT"
id: golangci_lint
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v${{ steps.golangci_lint.outputs.version }}
args: --timeout=30m
18 changes: 14 additions & 4 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,26 @@ run = "golangci-lint run"
alias = "format"
description = "Format code"
run = [
"go mod tidy",
"gofmt -s -w .",
"goimports -w .",
"shfmt -w -i 2 -ci -sr .",
"go mod tidy",
"gofmt -s -w .",
"goimports -w .",
"shfmt -w .",
"bun node_modules/.bin/prettier --write '**/*.{json,yaml,yml,md,jsonschema.json}'",
]

## <<Stencil::Block(custom)>>
[tasks.generate]
description = "Generate code and documentation"
run = ["go generate ./...", "mise run docgen", "mise run schemagen"]

[tasks.docgen]
description = "Generate documentation based on Stencil template functions"
run = "go run ./tools/docgen/docgen.go"

[tasks.schemagen]
description = "Generate JSON schema files for stencil configuration files"
run = "go run ./tools/schemagen/schemagen.go"

[tasks.next-version]
description = """Get the version number that would be released if a release was ran right now.
Pass --rc to get the next release candidate version.
Expand Down
31 changes: 14 additions & 17 deletions .mise/tasks/changelog-release
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,27 @@ args=("mise" "run" "changelog" "--")
# If we're on a non-rc version, use the current tag, otherwise use
# unreleased.
if [[ $CURRENT_TAG == *"-rc"* ]]; then
# Get the previous rc version.
# shellcheck disable=SC2001
PREVIOUS_RC_TAG=$(git tag --list --sort=-v:refname |
grep -E "$(sed 's/-rc\.[0-9]*//' <<<"$CURRENT_TAG")" | grep -v "$CURRENT_TAG" |
head -n 1 || true)
# Get the previous rc version.
# shellcheck disable=SC2001
PREVIOUS_RC_TAG=$(git tag --list --sort=-v:refname |
grep -E "$(sed 's/-rc\.[0-9]*//' <<<"$CURRENT_TAG")" | grep -v "$CURRENT_TAG" |
head -n 1 || true)

if [[ -z $PREVIOUS_RC_TAG ]]; then
args+=("--unreleased")
else
echo "Previous rc tag: $PREVIOUS_RC_TAG" >&2
args+=("--" "$PREVIOUS_RC_TAG..$CURRENT_TAG")
fi
if [[ -z $PREVIOUS_RC_TAG ]]; then
args+=("--unreleased")
else
echo "Previous rc tag: $PREVIOUS_RC_TAG" >&2
args+=("--" "$PREVIOUS_RC_TAG..$CURRENT_TAG")
fi
else
args+=("--current")
args+=("--current")
fi

# Run mise to generate the changelog.
"${args[@]}"

# If we're on a rc version, fix the header.
if [[ $CURRENT_TAG == *"-rc"* ]]; then
sed -i.bak "s/^## \[unreleased\]/## $CURRENT_TAG/" CHANGELOG.md
rm CHANGELOG.md.bak
sed -i.bak "s/^## \[unreleased\]/## $CURRENT_TAG/" CHANGELOG.md
rm CHANGELOG.md.bak
fi

bun install
bun prettier --write CHANGELOG.md
16 changes: 8 additions & 8 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"recommendations": [
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"golang.go",
"timonwong.shellcheck",
"redhat.vscode-yaml",
"foxundermoon.shell-format"
]
"recommendations": [
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"golang.go",
"timonwong.shellcheck",
"redhat.vscode-yaml",
"foxundermoon.shell-format"
]
}
Loading

0 comments on commit 5daa92d

Please sign in to comment.