Skip to content

Commit a504537

Browse files
committed
Update github workflow
1 parent 50e3c2e commit a504537

2 files changed

Lines changed: 88 additions & 36 deletions

File tree

.github/workflows/build.yml

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,33 @@ on:
55
branches:
66
- main
77
- master
8-
schedule:
9-
# rebuild everyday at 2:51
10-
# TIP: Choose a random time here so not all repositories are build at once:
11-
# https://www.random.org/clock-times/?num=1&earliest=01%3A00&latest=08%3A00&interval=5&format=html&rnd=new
12-
- cron: '51 2 * * *'
138
workflow_dispatch:
9+
1410
jobs:
11+
release-check:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
is-release: ${{ steps.condition-check.outputs.match }}
15+
steps:
16+
- id: condition-check
17+
uses: actions-ecosystem/action-regex-match@v2
18+
with:
19+
# matches: package_name: vX.Y.Z -> vX.Y.Z where XYZ are digits (including release candidates: vX.Y.Z-rcN)
20+
# it detects a commit from goreleaser with a new nix package version.
21+
regex: '\s*[a-zA-Z][\w]+:\s*v\d+\.\d+\.\d+(-rc\d+)?\s*->\s*v\d+\.\d+\.\d+(-rc\d+)?'
22+
text: ${{ github.event.head_commit.message }}
23+
1524
tests:
25+
needs: release-check
1626
strategy:
1727
matrix:
18-
# Set this to notify the global nur package registry that changes are
19-
# available.
20-
#
21-
# The repo name as used in
22-
# https://github.com/nix-community/NUR/blob/master/repos.json
23-
nurRepo:
24-
- <YOUR_REPO_NAME>
25-
# Set this to cache your build results in cachix for faster builds
26-
# in CI and for everyone who uses your cache.
27-
#
28-
# Format: Your cachix cache host name without the ".cachix.org" suffix.
29-
# Example: mycache (for mycache.cachix.org)
30-
#
31-
# For this to work, you also need to set the CACHIX_SIGNING_KEY or
32-
# CACHIX_AUTH_TOKEN secret in your repository secrets settings in
33-
# Github found at
34-
# https://github.com/<your_githubname>/nur-packages/settings/secrets
35-
cachixName:
36-
- <YOUR_CACHIX_NAME>
3728
nixPath:
3829
- nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixpkgs-unstable.tar.gz
3930
- nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-unstable.tar.gz
4031
- nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-25.11.tar.gz
4132
runs-on: ubuntu-latest
33+
34+
if: needs.release-check.outputs.is-release != ''
4235
steps:
4336
- name: Checkout repository
4437
uses: actions/checkout@v5
@@ -51,14 +44,6 @@ jobs:
5144
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
5245
- name: Show nixpkgs version
5346
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
54-
- name: Setup cachix
55-
uses: cachix/cachix-action@v16
56-
# Don't replace <YOUR_CACHIX_NAME> here!
57-
if: ${{ matrix.cachixName != '<YOUR_CACHIX_NAME>' }}
58-
with:
59-
name: ${{ matrix.cachixName }}
60-
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
61-
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
6247
- name: Check evaluation
6348
run: |
6449
nix-env -f . -qa \* --meta --xml \
@@ -70,7 +55,27 @@ jobs:
7055
-I $PWD
7156
- name: Build nix packages
7257
run: nix shell -f '<nixpkgs>' nix-build-uncached -c nix-build-uncached ci.nix -A cacheOutputs
73-
- name: Trigger NUR update
74-
# Don't replace <YOUR_REPO_NAME> here!
75-
if: ${{ matrix.nurRepo != '<YOUR_REPO_NAME>' }}
76-
run: curl -XPOST "https://nur-update.nix-community.org/update?repo=${{ matrix.nurRepo }}"
58+
59+
add-pkg:
60+
permissions:
61+
contents: write
62+
needs: [release-check, tests]
63+
runs-on: ubuntu-latest
64+
65+
if: needs.release-check.outputs.is-release != ''
66+
steps:
67+
- name: Checkout repository
68+
uses: actions/checkout@v5
69+
- name: Make addpkg script executable
70+
run: chmod +x ./addpkg.sh
71+
- name: Execute addpkg.sh to update nix package's catalog
72+
run: ./addpkg.sh step-agent-plugin
73+
- name: Add and Commit default.nix
74+
uses: EndBug/add-and-commit@v9 # Use the specific action
75+
with:
76+
add: 'default.nix' # Specifies the file(s) to add
77+
message: 'Added new nix package version' # The commit message
78+
author_name: 'github-actions[bot]'
79+
author_email: 'github-actions[bot]@users.noreply.github.com'
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

addpkg.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
[ $# -lt 1 ] && {
4+
echo "usage: $0 <package_name>"
5+
exit 1
6+
}
7+
8+
pkg="$1"
9+
pkg_with_version=$(basename $(ls -1 pkgs/${pkg}/${pkg}_* | sort -Vr | head -n 1) .nix)
10+
pkg_name="$(echo ${pkg_with_version} | tr '.' '_')"
11+
nix_entry="pkgs.callPackage ./pkgs/${pkg}/${pkg_with_version}.nix { };"
12+
13+
unameOut="$(uname -s)"
14+
OS=Linux
15+
16+
case "${unameOut}" in
17+
Darwin*) OS=Mac ;;
18+
esac
19+
20+
if [ "$OS" = "Mac" ]; then
21+
xsed() {
22+
sed -i "" "$@"
23+
}
24+
else
25+
xsed() {
26+
sed -i "$@"
27+
}
28+
fi
29+
30+
if ! grep -Eqs "${pkg_with_version}[[:blank:]]*=" default.nix; then
31+
echo "Adding new package entry to default.nix: pkg=$pkg version=$version"
32+
33+
xsed "/<package-list>/a\\
34+
${pkg_name} = ${nix_entry}" default.nix
35+
fi
36+
37+
# patch default package name to point to the latest version
38+
if ! grep -Eqs "${pkg}[[:blank:]]*=" default.nix; then
39+
echo "Adding default $pkg package entry..."
40+
41+
xsed "/<package-list>/a\\
42+
${pkg} = ${nix_entry}" default.nix
43+
else
44+
echo "Updating $pkg to point to new version $version"
45+
46+
xsed "s#^.*${pkg} *=.*\$# ${pkg} = ${nix_entry}#" default.nix
47+
fi

0 commit comments

Comments
 (0)