Skip to content

Commit

Permalink
Dynamic matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella committed Nov 2, 2023
1 parent df26695 commit e592639
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
29 changes: 13 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@ concurrency:
cancel-in-progress: true

jobs:
pre-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v22
- run: echo "package=$(./foo)" >> "$GITHUB_OUTPUT"
id: foo
outputs:
package: ${{ steps.foo.ouputs.package }}

build:
strategy:
# TODO: Create a dynamic matrix
matrix:
runner:
- os: macos-latest
system: x86_64-darwin
- os: ubuntu-latest
system: x86_64-linux
package:
- name: terraform-1_6_3
version: 1.6.3
allow_unfree: 1
# - name: terraform-1_6_1
# version: 1.6.1
# allow_unfree: 1
# - name: terraform-1_6_0
# version: 1.6.0
# allow_unfree: 1
# - name: terraform-1_5_7
# version: 1.5.7
# allow_unfree: 0
#
package: ${{ needs.pre-build.outputs.package }}
runs-on: ${{ matrix.runner.os }}
needs: [pre-build]
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v22
Expand All @@ -42,4 +39,4 @@ jobs:
id: nix-build
env:
NIXPKGS_ALLOW_UNFREE: ${{ matrix.package.allow_unfree }}
- run: cachix pin nixpkgs-terraform v${{ matrix.package.version }}-${{ matrix.runner.system }} ${{ steps.nix-build.outputs.out-paths }} --keep-revisions 1
# - run: cachix pin nixpkgs-terraform v${{ matrix.package.version }}-${{ matrix.runner.system }} ${{ steps.nix-build.outputs.out-paths }} --keep-revisions 1
17 changes: 17 additions & 0 deletions foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p python3Packages.semver

# vi: ft=python

import json
import semver

def foo(version):
splitted_version = version.split(".")
package_suffix = "_".join(splitted_version)
return { "version": version, "package": f"terraform-{package_suffix}", "allow_unfree": 1 if semver.compare(version, "1.6.0") >= 0 else 0 }

with open("versions.json") as f:
versions = json.load(f)
result = list(map(foo, versions))
print(json.dumps(result))

0 comments on commit e592639

Please sign in to comment.