From 984deb9ba31f26124cc7498c66f80b8650ebe460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Weisbarth?= Date: Wed, 21 Feb 2024 14:25:32 +0100 Subject: [PATCH 01/12] Add flake; --- .envrc | 11 ++++++++-- .gitignore | 8 +++----- flake.lock | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc index c8046b5..59993eb 100644 --- a/.envrc +++ b/.envrc @@ -1,2 +1,9 @@ -export GOPATH=$PWD -export PATH=$GOPATH/bin:$PATH +use_strict + +# export GOPATH=$PWD +# export PATH=$GOPATH/bin:$PATH + +if has nix +then + use flake +fi \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8e1d498..4d7a4fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ -/out/ -/pkg/ -/bin/ -.idea -build +# Nix build-results +/result +/result-* diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a78eaba --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "id": "flake-utils", + "type": "indirect" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1708294118, + "narHash": "sha256-evZzmLW7qoHXf76VCepvun1esZDxHfVRFUJtumD7L2M=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e0da498ad77ac8909a980f07eff060862417ccf7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a298e0b --- /dev/null +++ b/flake.nix @@ -0,0 +1,59 @@ +{ + description = '' + Flake for the cf-cli-plugin for app-autoscaler + + For more on app-autoscaler, see: + ''; + + inputs = { + nixpkgs.url = github:NixOS/nixpkgs/nixos-23.11; + }; + + outputs = { self, nixpkgs, flake-utils }: + let + supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + + # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + + # Nixpkgs instantiated for supported system types. + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); + in flake-utils.lib.eachSystem supportedSystems (system: { + packages = { + app-autoscaler-cli-plugin = nixpkgsFor.${system}.buildGoModule rec { + pname = "app-autoscaler-cli-plugin"; + version = + let + lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; + in "${builtins.substring 0 8 lastModifiedDate}-dev"; + src = ./.; + vendorHash = "sha256-NzEStcOv8ZQsHOA8abLABKy+ZE3/SiYbRD/ZVxo0CEk="; + + doCheck = false; + + meta = { + description = '' + App-AutoScaler plug-in provides the command line interface to manage + [App AutoScaler]() + policies, retrieve metrics and scaling event history. + ''; + homepage = "https://github.com/cloudfoundry/app-autoscaler-cli-plugin"; + license = [nixpkgsLib.licenses.apsl20]; + }; + }; + }; + + devShells = + let + nixpkgs = nixpkgsFor.${system}; + in { + default = nixpkgs.mkShell { + buildInputs = with nixpkgs; [ + delve + go + gopls + ]; + }; + }; + }); +} \ No newline at end of file From 70bafbcfb9c3a8c19d13b645223a83702255b34c Mon Sep 17 00:00:00 2001 From: Josua Geiger Date: Thu, 22 Feb 2024 10:48:20 +0100 Subject: [PATCH 02/12] fix build --- scripts/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build b/scripts/build index 05a459b..6b71858 100755 --- a/scripts/build +++ b/scripts/build @@ -4,4 +4,4 @@ set -e ROOT_DIR=$(cd $(dirname $(dirname $0)) && pwd) -go build -o $ROOT_DIR/out/ascli cli \ No newline at end of file +go build -o $ROOT_DIR/out/ascli/cli \ No newline at end of file From 7af1f97f7f95ee08d8e413745596401c730d53c0 Mon Sep 17 00:00:00 2001 From: joergdw Date: Thu, 22 Feb 2024 11:27:41 +0100 Subject: [PATCH 03/12] Fix official URL Co-authored-by: geigerj0 <112163019+geigerj0@users.noreply.github.com> --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index a298e0b..aa04c50 100644 --- a/flake.nix +++ b/flake.nix @@ -34,7 +34,7 @@ meta = { description = '' App-AutoScaler plug-in provides the command line interface to manage - [App AutoScaler]() + [App AutoScaler]() policies, retrieve metrics and scaling event history. ''; homepage = "https://github.com/cloudfoundry/app-autoscaler-cli-plugin"; From ea524b923adb5c84eb6cc577915f14ad61095b96 Mon Sep 17 00:00:00 2001 From: joergdw Date: Thu, 22 Feb 2024 11:28:11 +0100 Subject: [PATCH 04/12] Fix strictness Co-authored-by: geigerj0 <112163019+geigerj0@users.noreply.github.com> --- .envrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.envrc b/.envrc index 59993eb..3ad770b 100644 --- a/.envrc +++ b/.envrc @@ -1,4 +1,4 @@ -use_strict +strict_env # export GOPATH=$PWD # export PATH=$GOPATH/bin:$PATH From 147f05253fea1ebddd7bc2d16793f9ea340ebacd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Weisbarth?= Date: Thu, 22 Feb 2024 11:45:22 +0100 Subject: [PATCH 05/12] Include review-findings; --- NOTICE | 2 +- flake.nix | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/NOTICE b/NOTICE index 7a0705f..47d64cc 100644 --- a/NOTICE +++ b/NOTICE @@ -4,5 +4,5 @@ This project is licensed to you under the Apache License, Version 2.0 (the "Lice You may not use this project except in compliance with the License. This project may include a number of subcomponents with separate copyright notices -and license terms. Your use of these subcomponents is subject to the terms and +and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file. diff --git a/flake.nix b/flake.nix index aa04c50..128a352 100644 --- a/flake.nix +++ b/flake.nix @@ -27,6 +27,9 @@ lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; in "${builtins.substring 0 8 lastModifiedDate}-dev"; src = ./.; + + # πŸ”¨πŸš§ To-do: Create automation to get that updated if necessary per pull-request. + # As long as this automation does not exist, it needs to be updated manually. vendorHash = "sha256-NzEStcOv8ZQsHOA8abLABKy+ZE3/SiYbRD/ZVxo0CEk="; doCheck = false; @@ -38,7 +41,7 @@ policies, retrieve metrics and scaling event history. ''; homepage = "https://github.com/cloudfoundry/app-autoscaler-cli-plugin"; - license = [nixpkgsLib.licenses.apsl20]; + license = [nixpkgs.lib.licenses.apsl20]; }; }; }; From e4d5c27beebf0e271ff91a77d1471f4af7ad1d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Weisbarth?= Date: Tue, 14 May 2024 14:37:31 +0200 Subject: [PATCH 06/12] Copy tidy-up-job from app-autoscaler-release; --- .github/workflows/tidy_go_mod.yaml | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/tidy_go_mod.yaml diff --git a/.github/workflows/tidy_go_mod.yaml b/.github/workflows/tidy_go_mod.yaml new file mode 100644 index 0000000..45b6d58 --- /dev/null +++ b/.github/workflows/tidy_go_mod.yaml @@ -0,0 +1,39 @@ +name: Check if go.mod is tidy +on: + pull_request: + +concurrency: + group: "${{ github.workflow }}/${{ github.ref }}" + cancel-in-progress: true + +jobs: + check-tidy-go-mod: + name: ensure that go mod tidy has run + runs-on: ubuntu-latest + container: + image: ghcr.io/cloudfoundry/app-autoscaler-release-tools:main + steps: + - uses: actions/checkout@v4 + + - name: Trust my checkout + run: git config --global --add safe.directory "${GITHUB_WORKSPACE}" + + - name: run go mod tidy on all .mod's + shell: bash + run: | + #! /usr/bin/env bash + set -eu -o pipefail + + make generate-fakes + make generate-openapi-generated-clients-and-servers + make go-mod-tidy + + - name: Check if there is any change + id: get_changes + run: echo "changed=$(git status --porcelain | wc -l)" >> $GITHUB_OUTPUT + + - name: Process changes + if: steps.get_changes.outputs.changed != 0 + run: | + echo "::error::go.mod is not tidy, run make go-mod-tidy to tidy" + exit 1 From b9f4ac1eb78da7c6cd65bbfddbacc070a0fbf0ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Weisbarth?= Date: Tue, 14 May 2024 14:57:22 +0200 Subject: [PATCH 07/12] Auto-update Nix-hashes; --- .github/workflows/nix_adapt_hashes.yaml | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/nix_adapt_hashes.yaml diff --git a/.github/workflows/nix_adapt_hashes.yaml b/.github/workflows/nix_adapt_hashes.yaml new file mode 100644 index 0000000..85b9353 --- /dev/null +++ b/.github/workflows/nix_adapt_hashes.yaml @@ -0,0 +1,55 @@ +name: Adapt Nix hashes +on: + workflow_call: # 🚧 To-do: Remove this debug code. + pull_request: + branches: + - master + paths: + - "go.mod" + - "go.sum" + +concurrency: + group: "${{ github.workflow }}/${{ github.ref }}" + cancel-in-progress: true + +jobs: + check-tidy-go-mod: + name: Adapt the hashes in Nix-package-definitions. + runs-on: ubuntu-latest + container: + image: ghcr.io/cloudfoundry/app-autoscaler-release-tools:main + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + # With push token that can trigger new PR jobs. + token: ${{ secrets.APP_AUTOSCALER_CI_TOKEN }} + + - name: Install Nix + uses: cachix/install-nix-action@v26 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install nix-update + run: nix profile install 'nixpkgs/nixos-unstable#nix-update' + + - name: Run nix-update + shell: bash + run: | + #! /usr/bin/env bash + set -eu -o pipefail + + nix-update 'app-autoscaler-cli-plugin' --flake + + declare -i -r num_changed_files="$(git status --porcelain | wc --lines)" + if ((num_changed_files > 0)) + then + echo 'Changes to some files were necessary!' + declare -r tidy_message='πŸ€–πŸ¦ΎπŸ› οΈ Update Nix-package-hashes' + git add . + git commit --message="${tidy_message}" + git push + else + echo 'No hash-changes necessary!' + fi + echo '🏁' \ No newline at end of file From cc9e9208b0cbc431642f2acf53977ae719c426b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Weisbarth?= Date: Tue, 14 May 2024 15:01:34 +0200 Subject: [PATCH 08/12] Remove workflow and trigger the hash-generation as well on workflow-change; --- .github/workflows/nix_adapt_hashes.yaml | 10 ++++++- .github/workflows/tidy_go_mod.yaml | 39 ------------------------- 2 files changed, 9 insertions(+), 40 deletions(-) delete mode 100644 .github/workflows/tidy_go_mod.yaml diff --git a/.github/workflows/nix_adapt_hashes.yaml b/.github/workflows/nix_adapt_hashes.yaml index 85b9353..0a27323 100644 --- a/.github/workflows/nix_adapt_hashes.yaml +++ b/.github/workflows/nix_adapt_hashes.yaml @@ -1,10 +1,18 @@ name: Adapt Nix hashes on: - workflow_call: # 🚧 To-do: Remove this debug code. + workflow_dispatch: {} # 🚧 To-do: Remove this debug code. pull_request: branches: - master paths: + - ".github/workflows/nix_adapt_hashes.yaml" + - "go.mod" + - "go.sum" + push: + branches: + - master + paths: + - ".github/workflows/nix_adapt_hashes.yaml" - "go.mod" - "go.sum" diff --git a/.github/workflows/tidy_go_mod.yaml b/.github/workflows/tidy_go_mod.yaml deleted file mode 100644 index 45b6d58..0000000 --- a/.github/workflows/tidy_go_mod.yaml +++ /dev/null @@ -1,39 +0,0 @@ -name: Check if go.mod is tidy -on: - pull_request: - -concurrency: - group: "${{ github.workflow }}/${{ github.ref }}" - cancel-in-progress: true - -jobs: - check-tidy-go-mod: - name: ensure that go mod tidy has run - runs-on: ubuntu-latest - container: - image: ghcr.io/cloudfoundry/app-autoscaler-release-tools:main - steps: - - uses: actions/checkout@v4 - - - name: Trust my checkout - run: git config --global --add safe.directory "${GITHUB_WORKSPACE}" - - - name: run go mod tidy on all .mod's - shell: bash - run: | - #! /usr/bin/env bash - set -eu -o pipefail - - make generate-fakes - make generate-openapi-generated-clients-and-servers - make go-mod-tidy - - - name: Check if there is any change - id: get_changes - run: echo "changed=$(git status --porcelain | wc -l)" >> $GITHUB_OUTPUT - - - name: Process changes - if: steps.get_changes.outputs.changed != 0 - run: | - echo "::error::go.mod is not tidy, run make go-mod-tidy to tidy" - exit 1 From f898fd6c0799ae5ad1846e2ae5616ccf653a4cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Weisbarth?= Date: Tue, 14 May 2024 15:04:58 +0200 Subject: [PATCH 09/12] Update flake-inputs; --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index a78eaba..b895ef2 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -19,11 +19,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1708294118, - "narHash": "sha256-evZzmLW7qoHXf76VCepvun1esZDxHfVRFUJtumD7L2M=", + "lastModified": 1715542476, + "narHash": "sha256-FF593AtlzQqa8JpzrXyRws4CeKbc5W86o8tHt4nRfIg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e0da498ad77ac8909a980f07eff060862417ccf7", + "rev": "44072e24566c5bcc0b7aa9178a0104f4cfffab19", "type": "github" }, "original": { From e896db48505f5069968fd6d23d66a8f0dc88e002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Weisbarth?= Date: Tue, 14 May 2024 15:18:44 +0200 Subject: [PATCH 10/12] Fix name of the target-branch; --- .github/workflows/nix_adapt_hashes.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nix_adapt_hashes.yaml b/.github/workflows/nix_adapt_hashes.yaml index 0a27323..3d221d9 100644 --- a/.github/workflows/nix_adapt_hashes.yaml +++ b/.github/workflows/nix_adapt_hashes.yaml @@ -3,14 +3,14 @@ on: workflow_dispatch: {} # 🚧 To-do: Remove this debug code. pull_request: branches: - - master + - main paths: - ".github/workflows/nix_adapt_hashes.yaml" - "go.mod" - "go.sum" push: branches: - - master + - main paths: - ".github/workflows/nix_adapt_hashes.yaml" - "go.mod" From ccbb307988f068eaa2054735efe2f1dbb70ac9e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Weisbarth?= Date: Tue, 14 May 2024 15:43:47 +0200 Subject: [PATCH 11/12] =?UTF-8?q?=F0=9F=9A=A7=E2=86=92=F0=9F=90=A7=20Switc?= =?UTF-8?q?h=20image;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/nix_adapt_hashes.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/nix_adapt_hashes.yaml b/.github/workflows/nix_adapt_hashes.yaml index 3d221d9..b398766 100644 --- a/.github/workflows/nix_adapt_hashes.yaml +++ b/.github/workflows/nix_adapt_hashes.yaml @@ -24,8 +24,6 @@ jobs: check-tidy-go-mod: name: Adapt the hashes in Nix-package-definitions. runs-on: ubuntu-latest - container: - image: ghcr.io/cloudfoundry/app-autoscaler-release-tools:main steps: - uses: actions/checkout@v4 with: From 65fe01aa36ecc4b26b3d944c1e58e38dcd79d442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Weisbarth?= Date: Tue, 14 May 2024 15:51:14 +0200 Subject: [PATCH 12/12] Minor changes; --- .envrc | 3 --- .gitignore | 5 ++++- scripts/build | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.envrc b/.envrc index 3ad770b..5898e78 100644 --- a/.envrc +++ b/.envrc @@ -1,8 +1,5 @@ strict_env -# export GOPATH=$PWD -# export PATH=$GOPATH/bin:$PATH - if has nix then use flake diff --git a/.gitignore b/.gitignore index 4d7a4fb..0f8b21d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ -# Nix build-results +# Editor-configurations +.idea + +# ❄ Nix build-results /result /result-* diff --git a/scripts/build b/scripts/build index 6b71858..2e06a1e 100755 --- a/scripts/build +++ b/scripts/build @@ -1,7 +1,7 @@ -#!/bin/bash +#! /usr/bin/env bash set -e -ROOT_DIR=$(cd $(dirname $(dirname $0)) && pwd) +ROOT_DIR="$(cd $(dirname $(dirname $0)) && pwd)" -go build -o $ROOT_DIR/out/ascli/cli \ No newline at end of file +go build -o "${ROOT_DIR}/out/ascli/cli" \ No newline at end of file