From eaf7c15a8fc1386d734ea14d74be0719f8750638 Mon Sep 17 00:00:00 2001 From: Vegard Stenhjem Hagen Date: Wed, 16 Jul 2025 15:39:07 +0200 Subject: [PATCH] feat(ci): only run tofu fmt when necessary Signed-off-by: Vegard Hagen --- .github/.devcontainer/Containerfile | 9 +++++---- .github/workflows/tofu-format.yaml | 25 ++++++++++--------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/.github/.devcontainer/Containerfile b/.github/.devcontainer/Containerfile index fa110dc..2eabac2 100644 --- a/.github/.devcontainer/Containerfile +++ b/.github/.devcontainer/Containerfile @@ -2,13 +2,14 @@ FROM docker.io/ubuntu:24.04 ARG TARGETARCH -ARG USER_ID=1000 -ARG USER_GID=1000 +ARG USER_ID=1001 +ARG USER_GID=1001 ARG USERNAME=dev -RUN userdel ubuntu && \ - rm -rf /home/ubuntu +# Remove ubuntu user +RUN userdel -r ubuntu +# Install common packages RUN apt-get update && \ apt-get install -y --no-install-recommends \ apt-transport-https \ diff --git a/.github/workflows/tofu-format.yaml b/.github/workflows/tofu-format.yaml index 4409098..d37a1cf 100644 --- a/.github/workflows/tofu-format.yaml +++ b/.github/workflows/tofu-format.yaml @@ -1,4 +1,4 @@ -name: OpenTofu validation +name: Tofu format on: push: @@ -9,31 +9,26 @@ on: - '**.tfvars' - '**.tftpl' pull_request: - branches: [ main ] - pull_request_target: - branches: [ main ] + types: [ opened, synchronize ] + branches: [ '**' ] + paths: + - '**.tf' + - '**.tofu' + - '**.tfvars' + - '**.tftpl' jobs: tofu-format: - name: Validate + name: run tofu format runs-on: ubuntu-latest permissions: contents: read - env: - TOFU_DIR: tofu steps: - name: Checkout uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 - - name: Login to GitHub Container Registry - uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 #v3.4.0 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Tofu format uses: docker://ghcr.io/vehagn/homelab-devcontainer with: - args: tofu -chdir=${{ env.TOFU_DIR }} fmt -recursive -diff -check + args: tofu fmt -recursive -diff -check