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

feat(ci): Automatically update Nix hashes #245

Merged
merged 1 commit into from
Mar 13, 2025
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
72 changes: 66 additions & 6 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,78 @@ on:
- main
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write

jobs:
builds:
runs-on: ubuntu-latest
nix-update:
name: Update Nix hashes
runs-on: ubuntu-24.04

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Nix
uses: cachix/install-nix-action@v30
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
token: ${{ secrets.PAT }}

- name: Setup Nix
uses: DeterminateSystems/nix-installer-action@v16

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v8

- name: Setup Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'

- name: Update version and vendor hashes in Nix derivation
id: nix-update-hashes
run: |
nix develop .#ci --command sh <<'EOF'
VERSION=$(git describe --tags --abbrev=0)
nix-update --flake --version $VERSION gose
EOF

git diff --quiet || echo "changed=true" >> "$GITHUB_OUTPUT"

- name: Commit changes
id: git-commit
if: steps.nix-update-hashes.outputs.changed == 'true'
run: |
LAST_AUTHOR=$(git log -1 --pretty=format:"%ae")
RENOVATE_AUTHOR="29139614+renovate[bot]@users.noreply.github.com"

if [ "${LAST_AUTHOR}" = "${RENOVATE_AUTHOR}" ]; then
git commit --all --amend --no-edit
git push --force
else
git commit --all --signoff --message "fix(nix): Update version and hashes"
git push
fi


build:
name: Build
runs-on: ubuntu-24.04
needs:
- nix-update

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Nix
uses: DeterminateSystems/nix-installer-action@v16

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v8

- name: Run Nix build
run: nix build
Expand Down
4 changes: 2 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
lib,
}:
let
version = "0.8.0";
version = "0.9.0";

frontend = buildNpmPackage {
pname = "gose-frontend";
Expand All @@ -30,7 +30,7 @@ buildGoModule {

vendorHash = "sha256-U/umJ6McCuD0HARVMj1JXHOpVxcph16z7Y7i47Nf3cg=";

CGO_ENABLED = 0;
env.CGO_ENABLED = 0;

postInstall = ''
mv $out/bin/cmd $out/bin/gose
Expand Down
71 changes: 68 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 27 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
nix-update = {
url = "github:Mic92/nix-update";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
};

outputs =
{
self,
flake-utils,
nixpkgs,
nix-update,
}:
flake-utils.lib.eachDefaultSystem (
system:
Expand All @@ -22,17 +29,27 @@
};
in
{
devShell = pkgs.mkShell {
inputsFrom = [
self.packages.${system}.default
];
devShells = with pkgs; {
default = mkShell {
inputsFrom = [
self.packages.${system}.default
];

packages = with pkgs; [
golangci-lint
reuse
nodejs_22
goreleaser
];
packages = with pkgs; [
nix-update.packages.${system}.nix-update
golangci-lint
reuse
nodejs_22
goreleaser
];
};

ci = mkShell {
packages = [
nix-update.packages.${system}.nix-update
goreleaser
];
};
};

packages = rec {
Expand Down