diff --git a/.envrc b/.envrc index c8046b5..5898e78 100644 --- a/.envrc +++ b/.envrc @@ -1,2 +1,6 @@ -export GOPATH=$PWD -export PATH=$GOPATH/bin:$PATH +strict_env + +if has nix +then + use flake +fi \ No newline at end of file diff --git a/.github/workflows/nix_adapt_hashes.yaml b/.github/workflows/nix_adapt_hashes.yaml new file mode 100644 index 0000000..b398766 --- /dev/null +++ b/.github/workflows/nix_adapt_hashes.yaml @@ -0,0 +1,61 @@ +name: Adapt Nix hashes +on: + workflow_dispatch: {} # 🚧 To-do: Remove this debug code. + pull_request: + branches: + - main + paths: + - ".github/workflows/nix_adapt_hashes.yaml" + - "go.mod" + - "go.sum" + push: + branches: + - main + paths: + - ".github/workflows/nix_adapt_hashes.yaml" + - "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 + 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 diff --git a/.gitignore b/.gitignore index 8e1d498..0f8b21d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -/out/ -/pkg/ -/bin/ +# Editor-configurations .idea -build + +# ❄ Nix build-results +/result +/result-* 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.lock b/flake.lock new file mode 100644 index 0000000..b895ef2 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "id": "flake-utils", + "type": "indirect" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1715542476, + "narHash": "sha256-FF593AtlzQqa8JpzrXyRws4CeKbc5W86o8tHt4nRfIg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "44072e24566c5bcc0b7aa9178a0104f4cfffab19", + "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..128a352 --- /dev/null +++ b/flake.nix @@ -0,0 +1,62 @@ +{ + 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 = ./.; + + # πŸ”¨πŸš§ 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; + + 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 = [nixpkgs.lib.licenses.apsl20]; + }; + }; + }; + + devShells = + let + nixpkgs = nixpkgsFor.${system}; + in { + default = nixpkgs.mkShell { + buildInputs = with nixpkgs; [ + delve + go + gopls + ]; + }; + }; + }); +} \ No newline at end of file diff --git a/scripts/build b/scripts/build index 05a459b..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