mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-03-23 22:28:28 +01:00
Compare commits
No commits in common. "acc32c03432e0e5c1dcc4e332481e083e9e7d9d8" and "eb021286a51307a8169f0139e984dd24e58ab347" have entirely different histories.
acc32c0343
...
eb021286a5
2 changed files with 5 additions and 76 deletions
59
.github/workflows/ci.yml
vendored
59
.github/workflows/ci.yml
vendored
|
|
@ -73,71 +73,22 @@ jobs:
|
||||||
useDaemon: false
|
useDaemon: false
|
||||||
- name: Build server
|
- name: Build server
|
||||||
run: nix build .#nixosConfigurations.${{ matrix.server }}.config.system.build.toplevel --print-build-logs
|
run: nix build .#nixosConfigurations.${{ matrix.server }}.config.system.build.toplevel --print-build-logs
|
||||||
trigger-deploy:
|
deploy:
|
||||||
needs: [build-check, build-server]
|
needs: [build-check, build-server]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
|
||||||
previous-sha: ${{ steps.previous-sha.outputs.sha }}
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Get previous deploy SHA
|
|
||||||
id: previous-sha
|
|
||||||
run: |
|
|
||||||
sha=$(git ls-remote origin deploy | cut -f1)
|
|
||||||
printf "sha=%s" "$sha" >> "$GITHUB_OUTPUT"
|
|
||||||
- name: Push to deploy branch
|
- name: Push to deploy branch
|
||||||
run: git push --force origin HEAD:refs/heads/deploy
|
run: git push origin HEAD:deploy --force
|
||||||
await-deploy:
|
|
||||||
name: ${{ matrix.server }}
|
|
||||||
needs: [parse-flake, trigger-deploy]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
server: ${{ fromJson(needs.parse-flake.outputs.servers) }}
|
|
||||||
steps:
|
|
||||||
- name: Wait for deployment
|
|
||||||
timeout-minutes: 5
|
|
||||||
run: |
|
|
||||||
repo_url="https://github.com/${{ github.repository }}.git"
|
|
||||||
expected_sha="${{ github.sha }}"
|
|
||||||
branch="deployed/${{ matrix.server }}"
|
|
||||||
|
|
||||||
while true; do
|
|
||||||
deployed_sha=$(git ls-remote "$repo_url" "$branch" | cut -f1)
|
|
||||||
|
|
||||||
if [[ "$deployed_sha" == "$expected_sha" ]]; then
|
|
||||||
echo "✅ ${{ matrix.server }} deployed $expected_sha"
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
echo "⏳ ${{ matrix.server }}: deployed ${deployed_sha::7}, waiting for ${expected_sha::7}..."
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep 5
|
|
||||||
done
|
|
||||||
rollback-deploy:
|
|
||||||
if: always() && needs.await-deploy.result == 'failure'
|
|
||||||
needs: [trigger-deploy, await-deploy]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v5
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
token: ${{ secrets.PAT }}
|
|
||||||
- name: Rollback deploy branch
|
|
||||||
run: |
|
|
||||||
previous_sha="${{ needs.trigger-deploy.outputs.previous-sha }}"
|
|
||||||
echo "Rolling back deploy branch to $previous_sha"
|
|
||||||
git push --force origin "$previous_sha:refs/heads/deploy"
|
|
||||||
notify:
|
notify:
|
||||||
if: always()
|
if: always()
|
||||||
needs: [await-deploy]
|
needs: [deploy]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Notify success
|
- name: Notify success
|
||||||
if: needs.await-deploy.result == 'success'
|
if: needs.deploy.result == 'success'
|
||||||
run: |
|
run: |
|
||||||
curl -s \
|
curl -s \
|
||||||
-H "Title: CI: Deploy succeeded" \
|
-H "Title: CI: Deploy succeeded" \
|
||||||
|
|
@ -148,7 +99,7 @@ jobs:
|
||||||
-d "Commit \`${GITHUB_SHA::7}\` deployed successfully." \
|
-d "Commit \`${GITHUB_SHA::7}\` deployed successfully." \
|
||||||
https://ntfy.sh/splitleaf
|
https://ntfy.sh/splitleaf
|
||||||
- name: Notify failure
|
- name: Notify failure
|
||||||
if: needs.await-deploy.result == 'failure'
|
if: needs.deploy.result == 'failure'
|
||||||
run: |
|
run: |
|
||||||
curl -s \
|
curl -s \
|
||||||
-H "Title: CI: Deploy failed" \
|
-H "Title: CI: Deploy failed" \
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,11 @@
|
||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
inputs,
|
inputs,
|
||||||
pkgs,
|
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
cfg = config.custom.services.comin;
|
cfg = config.custom.services.comin;
|
||||||
|
|
||||||
postDeploymentScript =
|
|
||||||
pkgs.writeShellApplication {
|
|
||||||
name = "comin-post-deployment";
|
|
||||||
runtimeInputs = [ pkgs.git ];
|
|
||||||
text = ''
|
|
||||||
if [[ "$COMIN_STATUS" != "done" ]]; then
|
|
||||||
echo "Deployment not successful (status: $COMIN_STATUS), skipping branch update"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
token=$(cat "''${CREDENTIALS_DIRECTORY}/git-push-token")
|
|
||||||
repo_url="https://x-access-token:$token@github.com/SebastianStork/nixos-config.git"
|
|
||||||
|
|
||||||
git push --force "$repo_url" "$COMIN_GIT_SHA:refs/heads/deployed/$COMIN_HOSTNAME"
|
|
||||||
|
|
||||||
echo "Updated deployed/$COMIN_HOSTNAME to $COMIN_GIT_SHA"
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
|> lib.getExe;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [ inputs.comin.nixosModules.comin ];
|
imports = [ inputs.comin.nixosModules.comin ];
|
||||||
|
|
@ -56,7 +35,6 @@ in
|
||||||
listen_address = "127.0.0.1";
|
listen_address = "127.0.0.1";
|
||||||
port = cfg.metricsPort;
|
port = cfg.metricsPort;
|
||||||
};
|
};
|
||||||
postDeploymentCommand = postDeploymentScript;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue