Skip to content
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

chore: Sync to repo template #63

Merged
merged 10 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
{
"rules": {
"type-enum": [
2,
"always",
[
"chore",
"ci",
"deps",
"feat",
"fix",
"patch",
"style"
]
],
"subject-empty": [
2,
"never"
],
"type-case": [
2,
"always",
"lower-case"
],
"subject-case": [
0
],
"type-empty": [
2,
"never"
],
"scope-case": [
2,
"always",
"lower-case"
],
"scope-enum": [
0
],
"header-max-length": [
2,
"always",
120
]
}
"rules": {
"type-enum": [
2,
"always",
[
"chore",
"ci",
"deps",
"feat",
"fix",
"patch",
"style"
]
],
"subject-empty": [
2,
"never"
],
"type-case": [
2,
"always",
"lower-case"
],
"subject-case": [
0
],
"type-empty": [
2,
"never"
],
"scope-case": [
2,
"always",
"lower-case"
],
"scope-enum": [
0
],
"header-max-length": [
2,
"always",
120
]
}
}
19 changes: 19 additions & 0 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"template": "https://github.com/mirceanton/repository-templates",
"commit": "17fe5d3a477f09ed2e604098f2ae6e6be32eb340",
"checkout": null,
"context": {
"cookiecutter": {
"project_name": "talswitcher",
"repo_name": "talswitcher",
"project_description": "A simple tool to help manage multiple talosconfig files.",
"author": "Mircea-Pavel Anton",
"go_version": "1.23.0",
"_copy_without_render": [
".github/*"
],
"_template": "https://github.com/mirceanton/repository-templates"
}
},
"directory": "golang"
}
31 changes: 13 additions & 18 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
## ================================================================================================
# Utility versions
## ================================================================================================
ARG KUBECTL_VERSION=1.31.1@sha256:da4a9868e20d941636087cb8624a4bb441f5249d69e8f3d27e53c7d4d280a5f3
ARG TALOSCTL_VERSION=v1.8.0@sha256:08b8260e162391b7714466f36105902beb3dcac3d4fa1408b4f4838ddbb5b8ea
ARG TALHELPER_VERSION=v3.0.6@sha256:a6d40693ca004381fc6d436f608df755ca6a32b9215740d63db23498ba7bba64
ARG TASKFILE_VERSION=v3.38.0@sha256:308c4f5be86bffae3f956cbd7225c4fec69b0e7a89012120b818a10df45d7c59
ARG GOLINT_VERSION=v1.61.0-alpine@sha256:61e2d68adc792393fcb600340fe5c28059638d813869d5b4c9502392a2fb4c96
ARG GORELEASER_VERSION=v2.3.2@sha256:d62b4a18dfe3af7bd4da9e5954b496548ef04e73ae8f98cd75ba63a9ed4d73e5

ARG KUBECTL_VERSION=1.31.1@sha256:da4a9868e20d941636087cb8624a4bb441f5249d69e8f3d27e53c7d4d280a5f3
ARG TALOSCTL_VERSION=v1.8.0@sha256:08b8260e162391b7714466f36105902beb3dcac3d4fa1408b4f4838ddbb5b8ea


## ================================================================================================
# "Build" stage for utilities with docker images already present
## ================================================================================================
FROM bitnami/kubectl:${KUBECTL_VERSION} AS kubectl
FROM ghcr.io/siderolabs/talosctl:${TALOSCTL_VERSION} AS talosctl
FROM ghcr.io/budimanjojo/talhelper:${TALHELPER_VERSION} AS talhelper
FROM ghcr.io/mirceanton/taskfile:${TASKFILE_VERSION} AS taskfile
FROM golangci/golangci-lint:${GOLINT_VERSION} AS golangci-lint
FROM goreleaser/goreleaser:${GORELEASER_VERSION} AS goreleaser

FROM bitnami/kubectl:${KUBECTL_VERSION} AS kubectl
FROM ghcr.io/siderolabs/talosctl:${TALOSCTL_VERSION} AS talosctl

## ================================================================================================
## Main image
## ================================================================================================
FROM mcr.microsoft.com/devcontainers/go:1.23-bookworm@sha256:16c623ad4c8b5f2e45e51ba0d26229306be00bffe51826c3d9acde94188086f1 AS workspace

COPY --from=kubectl /opt/bitnami/kubectl/bin/kubectl /usr/local/bin/kubectl
RUN kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl.bash > /dev/null

# Install additional tools
COPY --from=taskfile /task /usr/local/bin/task
COPY --from=golangci-lint /usr/bin/golangci-lint /usr/local/bin/golangci-lint
COPY --from=goreleaser /usr/bin/goreleaser /usr/local/bin/goreleaser
COPY --from=talosctl /talosctl /usr/local/bin/talosctl
RUN talosctl completion bash | sudo tee /etc/bash_completion.d/talosctl.bash > /dev/null

COPY --from=talhelper /bin/talhelper /usr/local/bin/talhelper
RUN talhelper completion bash | sudo tee /etc/bash_completion.d/talhelper.bash > /dev/null
COPY --from=kubectl /opt/bitnami/kubectl/bin/kubectl /usr/local/bin/kubectl

COPY --from=golangci-lint /usr/bin/golangci-lint /usr/local/bin/golangci-lint
# Generate bash completions
RUN golangci-lint completion bash | sudo tee /etc/bash_completion.d/golangci-lint.bash > /dev/null

COPY --from=goreleaser /usr/bin/goreleaser /usr/local/bin/goreleaser
RUN goreleaser completion bash | sudo tee /etc/bash_completion.d/goreleaser.bash > /dev/null

COPY --from=taskfile /task /usr/local/bin/task
RUN kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl.bash > /dev/null
RUN talosctl completion bash | sudo tee /etc/bash_completion.d/talosctl.bash > /dev/null

USER vscode
ENTRYPOINT [ "/bin/bash", "-l", "-c" ]
90 changes: 1 addition & 89 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,93 +9,5 @@
},
"remoteUser": "vscode",
"containerUser": "vscode",
"updateRemoteUserUID": true,
"customizations": {
"vscode": {
"extensions": [
"golang.go",
"aaron-bond.better-comments",
"ms-azuretools.vscode-docker",
"davidanson.vscode-markdownlint",
"albert.TabOut",
"mhutchie.git-graph",
"bierner.emojisense",
"redhat.vscode-yaml",
"pkief.material-icon-theme",
"task.vscode-task",
"GitHub.copilot",
"foxundermoon.shell-format",
"DavidAnson.vscode-markdownlint"
],
"settings": {
"editor.fontFamily": "Cascadia Code",
"editor.fontSize": 14,
"editor.fontLigatures": true,
"editor.cursorBlinking": "phase",
"editor.bracketPairColorization.enabled": true,
"editor.bracketPairColorization.independentColorPoolPerBracketType": true,
"editor.guides.bracketPairs": true,
"editor.guides.bracketPairsHorizontal": true,
"editor.guides.highlightActiveBracketPair": true,
"editor.hover.delay": 500,
"editor.renderWhitespace": "boundary",
"editor.rulers": [
150,
200
],
"editor.stickyScroll.enabled": false,
"explorer.autoReveal": false,
"files.associations": {
"**/*.json5": "jsonc"
},
"files.trimTrailingWhitespace": true,
"editor.formatOnSave": true,
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000,
"workbench.iconTheme": "material-icon-theme",
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features",
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.quickSuggestions": {
"strings": true
},
"editor.suggest.insertMode": "replace"
},
"[yaml]": {
"editor.defaultFormatter": "redhat.vscode-yaml",
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.autoIndent": "keep",
"editor.quickSuggestions": {
"other": true,
"comments": false,
"strings": true
}
},
"[go]": {
"editor.defaultFormatter": "golang.go",
"editor.insertSpaces": false,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "always"
}
},
"[shellscript]": {
"editor.defaultFormatter": "foxundermoon.shell-format",
"files.eol": "\n"
},
"[markdown]": {
"editor.defaultFormatter": "DavidAnson.vscode-markdownlint",
"editor.wordWrap": "on"
},
"[dockerfile]": {
"editor.defaultFormatter": "ms-azuretools.vscode-docker",
"editor.quickSuggestions": {
"strings": true
}
}
}
}
}
"updateRemoteUserUID": true
}
106 changes: 106 additions & 0 deletions .github/workflows/cruft-sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Cruft Sync

on:
# Manual Trigger
workflow_dispatch: {}

# "Wet" Run hourly
schedule:
- cron: "0 * * * *"

jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
with:
python-version: "3.12"

- name: Install Cruft
run: pip3 install cruft

- name: Generate Token
uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
id: app-token
with:
app-id: "${{ secrets.BOT_APP_ID }}"
private-key: "${{ secrets.BOT_APP_PRIVATE_KEY }}"

- name: Checkout
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
fetch-depth: 0
token: "${{ steps.app-token.outputs.token }}"

- name: Check if the `cruft_update` branch already exists
id: check-branch
run: |
if git ls-remote --exit-code --heads origin cruft_update; then
echo "branch_exists=true" | tee "$GITHUB_OUTPUT"
else
echo "branch_exists=false" | tee "$GITHUB_OUTPUT"
fi

- name: Create the `cruft_update` branch
if: steps.check-branch.outputs.branch_exists == 'false'
run: git branch cruft_update

- name: Switch to the `cruft_update` branch
run: git switch cruft_update

- name: Check if a cruft update is available
id: check-cruft
run: |
if ! cruft check; then
echo "has_changes=true" | tee "$GITHUB_OUTPUT"
else
echo "has_changes=false" | tee "$GITHUB_OUTPUT"
fi

- name: Apply cruft update
if: steps.check-cruft.outputs.has_changes == 'true'
run: |
cruft update --skip-apply-ask --refresh-private-variables
git restore --staged .

- name: Configure Git User
if: steps.check-cruft.outputs.has_changes == 'true'
run: |
git config --global user.email "[email protected]"
git config --global user.name "Mr. Borboto"

- name: Commit and push changes
if: steps.check-cruft.outputs.has_changes == 'true'
run: |
git add -A
git commit -m "chore(cruft): apply template updates"
git push --set-upstream origin cruft_update

- name: Check if a pull request already exists
id: check-pr
env:
GH_TOKEN: "${{ steps.app-token.outputs.token }}"
run: |
PR_EXISTS=$(gh pr list --head cruft_update --json number | jq '. | length > 0')
echo "pr_exists=$PR_EXISTS" | tee "$GITHUB_OUTPUT"

- name: Compare the current branch with the main branch
id: check-changes
run: |
if git diff --quiet origin/main; then
echo "has_changes=false" | tee "$GITHUB_OUTPUT"
else
echo "has_changes=true" | tee "$GITHUB_OUTPUT"
fi

- name: Create pull request
if: steps.check-pr.outputs.pr_exists == 'false' && steps.check-changes.outputs.has_changes == 'true'
env:
GH_TOKEN: "${{ steps.app-token.outputs.token }}"
run: |
gh pr create \
--title "chore(cruft): Apply updates from template" \
--body "This PR adds the changes from the upstream template."
2 changes: 1 addition & 1 deletion .github/workflows/devcontainer-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: mirceanton/reusable-workflows/.github/workflows/reusable-docker-build-push.yaml@2dc165dbaca3733e48c4951e080807c372b64fd8 # v3.4.11
secrets: inherit
with:
image: "ghcr.io/mirceanton/talswitcher-devcontainer"
image: "ghcr.io/${{ github.repository }}-devcontainer"
platforms: linux/amd64
tags: test
context: ./.devcontainer
Expand Down
Loading