Skip to content

Avoid detached HEAD in Update workflow on push events #2517

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

Merged
merged 7 commits into from
Mar 30, 2021
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
36 changes: 26 additions & 10 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
steps:
- id: config
run: |
if [ "${{ github.event_name }}" == 'pull_request' ]
then
echo "::set-output name=ref::${{ github.event.pull_request.head.sha }}"
else
echo "::set-output name=ref::$GITHUB_SHA"
ref=${{ github.ref }}
if [ "${{ github.event_name }}" == 'pull_request' ]; then
ref="${{ github.event.pull_request.head.sha }}"
fi
ref="${ref#refs/heads/}"
echo "::set-output name=ref::$ref"

git config --global user.name github-actions
git config --global user.email [email protected]
Expand Down Expand Up @@ -47,6 +47,13 @@ jobs:
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
run: |
if [[ $GITHUB_EVENT_NAME == 'push' ]]; then
if git status -s -b | grep -q '^##.*(no branch)$'; then
echo 2>&1 "Error: Git is in detached HEAD state"
exit 1
fi
fi

if [ -n "$(git status --porcelain 'nix/')" ]; then
if [[ $GITHUB_EVENT_NAME == 'pull_request' ]]; then
echo 2>&1 "Error: found modified files"
Expand All @@ -58,6 +65,7 @@ jobs:
git push
else
echo 2>&1 "Error: event not supported: $GITHUB_EVENT_NAME"
exit 1
fi
fi

Expand All @@ -67,12 +75,12 @@ jobs:
steps:
- id: config
run: |
if [ "${{ github.event_name }}" == 'pull_request' ]
then
echo "::set-output name=ref::${{ github.event.pull_request.head.sha }}"
else
echo "::set-output name=ref::$GITHUB_SHA"
ref=${{ github.ref }}
if [ "${{ github.event_name }}" == 'pull_request' ]; then
ref="${{ github.event.pull_request.head.sha }}"
fi
ref="${ref#refs/heads/}"
echo "::set-output name=ref::$ref"

git config --global user.name github-actions
git config --global user.email [email protected]
Expand Down Expand Up @@ -103,6 +111,13 @@ jobs:
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
run: |
if [[ $GITHUB_EVENT_NAME == 'push' ]]; then
if git status -s -b | grep -q '^##.*(no branch)$'; then
echo 2>&1 "Error: Git is in detached HEAD state"
exit 1
fi
fi

if [ -n "$(git status --porcelain '*.hs')" ]; then
if [[ $GITHUB_EVENT_NAME == 'pull_request' ]]; then
echo 2>&1 "Error: found modified files"
Expand All @@ -114,5 +129,6 @@ jobs:
git push
else
echo 2>&1 "Error: event not supported: $GITHUB_EVENT_NAME"
exit 1
fi
fi
4 changes: 4 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ let
name = "kore-${version}";
paths = pkgs.lib.attrValues project.kore.components.exes;
};

# Change the compiler when updating our own resolver.
compiler-nix-name = "ghc8104";
index-state = "2021-02-09T00:00:00Z";
};

in default
23 changes: 23 additions & 0 deletions nix/fourmolu.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ default ? import ../default.nix {}
, checkMaterialization ? false
}:

let
sources = import ./sources.nix;

inherit (default) compiler-nix-name index-state;

fourmolu-project = default.pkgs.haskell-nix.cabalProject {
src = sources."fourmolu";
inherit checkMaterialization compiler-nix-name index-state;
materialized = ./fourmolu.nix.d;
};

inherit (fourmolu-project.fourmolu.components.exes) fourmolu;
in

fourmolu // {
passthru =
(fourmolu.passthru or {})
// { inherit (fourmolu-project.plan-nix.passthru) updateMaterialized; };
}
2 changes: 1 addition & 1 deletion nix/fourmolu.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env nix-shell
#!nix-shell ../shell.nix -i bash
#!nix-shell shell.fourmolu.nix -i bash

./scripts/remove-import-groups.sh
./scripts/fourmolu.sh
23 changes: 23 additions & 0 deletions nix/hpack.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ default ? import ../default.nix {}
, checkMaterialization ? false
}:

let
sources = import ./sources.nix;

inherit (default) compiler-nix-name index-state;

hpack-project = default.pkgs.haskell-nix.cabalProject {
src = sources."hpack";
inherit checkMaterialization compiler-nix-name index-state;
materialized = ./hpack.nix.d;
};

inherit (hpack-project.hpack.components.exes) hpack;
in

hpack // {
passthru =
(hpack.passthru or {})
// { inherit (hpack-project.plan-nix.passthru) updateMaterialized; };
}
2 changes: 1 addition & 1 deletion nix/rematerialize.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

nix-shell --run 'hpack -f kore'
nix-shell nix/shell.hpack.nix --run 'hpack -f kore'
$(nix-build --no-out-link -A rematerialize)
$(nix-build --no-out-link shell.nix -A passthru.rematerialize)
10 changes: 10 additions & 0 deletions nix/shell.fourmolu.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let
default = import ../default.nix {};
fourmolu = import ./fourmolu.nix {};
inherit (default) pkgs;
inherit (pkgs) fd;
in

pkgs.mkShell {
buildInputs = [ fourmolu fd ];
}
8 changes: 8 additions & 0 deletions nix/shell.hpack.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let
default = import ../default.nix {};
hpack = import ./hpack.nix {};
in

default.pkgs.mkShell {
buildInputs = [ hpack ];
}
21 changes: 5 additions & 16 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ let
inherit (pkgs) cabal-install ghcid stack;
inherit (pkgs) fd gnumake yq z3;

# Change the compiler when updating our own resolver.
compiler-nix-name = "ghc8104";
index-state = "2021-02-09T00:00:00Z";
inherit (default) compiler-nix-name index-state;

hls-project = import sources."nix-haskell-hls" {
ghcVersion = compiler-nix-name;
Expand All @@ -35,19 +33,9 @@ let
};
inherit (stylish-haskell-project.stylish-haskell.components.exes) stylish-haskell;

fourmolu-project = default.pkgs.haskell-nix.cabalProject {
src = sources."fourmolu";
inherit checkMaterialization compiler-nix-name index-state;
materialized = ./nix/fourmolu.nix.d;
};
inherit (fourmolu-project.fourmolu.components.exes) fourmolu;
fourmolu = import ./nix/fourmolu.nix { inherit default checkMaterialization; };

hpack-project = default.pkgs.haskell-nix.cabalProject {
src = sources."hpack";
inherit checkMaterialization compiler-nix-name index-state;
materialized = ./nix/hpack.nix.d;
};
inherit (hpack-project.hpack.components.exes) hpack;
hpack = import ./nix/hpack.nix { inherit default checkMaterialization; };

in

Expand All @@ -63,6 +51,7 @@ shellFor {
#!/bin/sh
${hlint-project.plan-nix.passthru.updateMaterialized}
${stylish-haskell-project.plan-nix.passthru.updateMaterialized}
${hpack-project.plan-nix.passthru.updateMaterialized}
${fourmolu.passthru.updateMaterialized}
${hpack.passthru.updateMaterialized}
'';
}