From 03b4acbc8b1bc8968095f553ed939c7a266e3fae Mon Sep 17 00:00:00 2001 From: C4 Patino Date: Wed, 5 Nov 2025 08:53:24 -0600 Subject: [PATCH] fix: modified ci format action to work with forgejo and added treemfmt support --- .forgejo/workflows/ci.yml | 65 ++++++++++++++++++++++++ .github/workflows/format.yml | 19 ------- flake.lock | 96 ++++++++++++++++++++++++++++++++++++ flake.nix | 30 +++++++++++ 4 files changed, 191 insertions(+), 19 deletions(-) create mode 100755 .forgejo/workflows/ci.yml delete mode 100755 .github/workflows/format.yml create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml new file mode 100755 index 0000000..33e1ffd --- /dev/null +++ b/.forgejo/workflows/ci.yml @@ -0,0 +1,65 @@ +name: ci + +on: + push: + branches: ["main"] + workflow_dispatch: + +env: + USER: runner + +jobs: + nix-fmt: + runs-on: ubuntu-latest + steps: + - name: install nix + uses: https://github.com/cachix/install-nix-action@v31.8.4 + with: + nix_path: nixpkgs=channel:nixos-unstable + - name: set up nix + run: | + mkdir -p ~/.config/nix + echo "experimental-features = nix-command flakes pipe-operators" >> ~/.config/nix/nix.conf + nix-channel --add https://nixos.org/channels/nixos-unstable nixpkgs + nix-channel --update + - name: set up nix-community cachix + uses: https://github.com/cachix/cachix-action@v16 + with: + name: nix-community + authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" + - name: setup git identity + run: | + git config --global user.name "forgejo-actions-bot" + git config --global user.email "actions@forgejo.local" + - name: import gpg key + env: + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + run: | + echo "$GPG_PRIVATE_KEY" | gpg --batch --import || true + KEYID=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec/{print $5;exit}') + git config --global user.signingkey "$KEYID" + git config --global commit.gpgsign true + echo "default-cache-ttl 3600" >> ~/.gnupg/gpg-agent.conf + echo RELOADAGENT | gpg-connect-agent + - name: checkout code + uses: actions/checkout@v5.0.0 + - name: run nix fmt + run: nix fmt + - name: check for changes + id: git_status + run: | + if [[ -n "$(git status --porcelain)" ]]; then + echo "changed=true" >> $GITHUB_OUTPUT + else + echo "changed=false" >> $GITHUB_OUTPUT + fi + - name: commit and push changes + if: steps.git_status.outputs.changed == 'true' + env: + TOKEN: ${{ secrets.ACTIONS_TOKEN }} + GITEA_SERVER: git.cpatino.com + GITEA_REPO: c4patino/yumevim + run: | + git add -A + git commit -S -m "style: autoformatting all files with treefmt" + git push "https://forgejo:${TOKEN}@${GITEA_SERVER}/${GITEA_REPO}.git" HEAD:main diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml deleted file mode 100755 index a2084c5..0000000 --- a/.github/workflows/format.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: ci - -on: - push: - branches: ["main"] - tags: ["v*.*.*"] - pull_request: - types: [opened, reopened, synchronize] - branches: ["*"] - workflow_dispatch: - -permissions: - contents: write - -jobs: - format: - uses: c4patino/actions/.github/workflows/format.yml@main - with: - language: lua diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4ed79ce --- /dev/null +++ b/flake.lock @@ -0,0 +1,96 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1762233356, + "narHash": "sha256-cGS3lLTYusbEP/IJIWGgnkzIl+FA5xDvtiHyjalGr4k=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ca534a76c4afb2bdc07b681dbc11b453bab21af8", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-25.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1761236834, + "narHash": "sha256-+pthv6hrL5VLW2UqPdISGuLiUZ6SnAXdd2DdUE+fV2Q=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d5faa84122bc0a1fd5d378492efce4e289f8eac1", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1762352490, + "narHash": "sha256-hOP4GxAmeXI43U1lIrKbWI2k35M1/T/i8iJrO9m/GzY=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "4ef3dfdbb5ddfb9e39999a2f2b0c2637277859d4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..674af47 --- /dev/null +++ b/flake.nix @@ -0,0 +1,30 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-25.05"; + flake-utils.url = "github:numtide/flake-utils"; + treefmt-nix.url = "github:numtide/treefmt-nix"; + }; + outputs = { + flake-utils, + nixpkgs, + treefmt-nix, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = import nixpkgs {inherit system;}; + + treefmtConfig = {...}: { + projectRootFile = "flake.nix"; + programs = { + alejandra.enable = true; + stylua.enable = true; + }; + }; + + treefmtEval = treefmt-nix.lib.evalModule pkgs (treefmtConfig {inherit pkgs;}); + in { + formatter = treefmtEval.config.build.wrapper; + } + ); +}