Skip to content

Commit a819efd

Browse files
authored
Test suite (#1)
* Added integration test * Added input for package.yaml location * Updated README.md to explain the new package-yaml-path input * Fixed description in action.yml * Added status badge for tests
1 parent 711d924 commit a819efd

File tree

6 files changed

+69
-5
lines changed

6 files changed

+69
-5
lines changed

.github/workflows/build-and-release.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v4
16+
uses: actions/checkout@v4.2.2
1717
with:
1818
fetch-depth: 0
1919
- name: Set up Node.js
20-
uses: actions/setup-node@v4
20+
uses: actions/setup-node@v4.4.0
2121
with:
2222
node-version: '20'
2323
- name: Install dependencies
@@ -38,7 +38,7 @@ jobs:
3838
git push origin ${{ github.event.inputs.tag }}
3939
- name: Create GitHub release
4040
id: create_release
41-
uses: softprops/action-gh-release@v2
41+
uses: softprops/action-gh-release@v2.3.2
4242
with:
4343
tag_name: ${{ github.event.inputs.tag }}
4444
generate_release_notes: true

.github/workflows/test.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Test Get Supported GHC Version Action
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
schedule:
8+
- cron: 0 5 * * 0 # every sunday 05:00 UTC
9+
10+
jobs:
11+
integration-test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/[email protected]
15+
- run: npm install
16+
- run: npm run build
17+
- name: Run action
18+
uses: ./
19+
with:
20+
package-yaml-path: examples/package.yaml
21+
id: ghc-version
22+
- name: Assert output
23+
run: |-
24+
if [ "${{ steps.ghc-version.outputs.ghc-version }}" != "8.10.7" ]; then
25+
exit 1
26+
fi

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
# Get Supported GHC Version
22

3+
[![Test Get Supported GHC Version Action](https://github.com/webdevred/get-supported-ghc/actions/workflows/test.yaml/badge.svg)](https://github.com/webdevred/get-supported-ghc/actions/workflows/test.yaml)
4+
35
This GitHub Action automatically detects the latest GHC (Glasgow Haskell Compiler) version compatible with your Haskell project's `base` dependency constraint in `package.yaml`.
46

57
Useful for CI/CD workflows where you want to install a GHC version that satisfies your project's dependency bounds.
68

9+
## Inputs
10+
11+
| Input | Description | Default | Required |
12+
|---------------------|------------------------------------------------------------|----------------|----------|
13+
| `package-yaml-path` | Path to your `package.yaml` file relative to the repo root | `package.yaml` | No |
14+
15+
## Outputs
16+
17+
| Output | Description |
18+
|---------------|----------------------------------------------|
19+
| `ghc-version` | The latest compatible GHC version to install |
20+
721
## Example Usage
822

923
```yaml
@@ -21,6 +35,8 @@ jobs:
2135
- name: Get latest supported GHC version
2236
id: get-ghc
2337
uses: webdevred/[email protected]
38+
with:
39+
package-yaml-path: examples/package.yaml
2440
- name: Set up GHC latest and Cabal
2541
id: setup-ghc
2642
uses: haskell-actions/[email protected]

action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
name: Get Supported GHC Version
22
description: Finds the latest GHC version that supports the base upper bound in your
3-
.cabal file.
3+
package.yaml file.
44

55
runs:
66
using: node20
77
main: index.js
88

9+
inputs:
10+
package-yaml-path:
11+
description: 'Path to package.yaml (default: package.yaml in repo root)'
12+
required: false
13+
default: package.yaml
14+
915
outputs:
1016
ghc-version:
1117
description: The GHC version to install

examples/package.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: my-haskell-package
2+
version: 0.1.0.0
3+
dependencies: [base >= 4.10 && < 4.15, containers, text]
4+
5+
library:
6+
exposed-modules: MyLib
7+
source-dirs: src
8+
ghc-options: -Wall

src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { exec } = require("child_process");
22
const fs = require("fs");
33
const path = require("path");
44
const yaml = require("js-yaml");
5+
const githubCore = require("@actions/core");
56

67
async function runCommand(cmd) {
78
return new Promise((resolve, reject) => {
@@ -49,8 +50,9 @@ function versionLess(v1, v2) {
4950
async function main() {
5051
try {
5152
const files = fs.readdirSync(process.cwd());
53+
const packageYamlPath = githubCore.getInput("package-yaml-path") || path.join(process.cwd(), "package.yaml");
5254

53-
const baseUpperBound = getBaseUpperBound(path.join(process.cwd(), "package.yaml"));
55+
const baseUpperBound = getBaseUpperBound(packageYamlPath);
5456

5557
const ghcupListStr = await runCommand("ghcup list -t ghc -r");
5658
const lines = ghcupListStr.split("\n").filter(Boolean);
@@ -61,6 +63,12 @@ async function main() {
6163
return { version: match[1], base: match[2] };
6264
}).filter(Boolean);
6365

66+
if(ghcupList.length > 0) {
67+
console.log(`Found ${ghcupList.length} GHC versions`);
68+
} else {
69+
throw new Error('Failed to get GHC versions from GHCup');
70+
}
71+
6472
const validVersions = ghcupList.filter(ghcEntry => {
6573
return versionLess(ghcEntry.base, baseUpperBound);
6674
});

0 commit comments

Comments
 (0)