Skip to content

Commit

Permalink
Add config option
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Jan 2, 2025
1 parent 7a55b60 commit eb8eee7
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 65 deletions.
47 changes: 38 additions & 9 deletions .github/workflows/test-ghcup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ jobs:
- uses: actions/checkout@v4

- uses: ./
with:
stack-hook: true
version: ${{ matrix.version }}

- run: ghcup config
- run: ghcup debug-info
Expand Down Expand Up @@ -53,12 +50,6 @@ jobs:
- if: runner.os == 'Windows'
run: ghcup run -m sh -- -c 'pacman --version'

- name: Stack hook test
run: |
ghcup install stack latest
cat $(stack path --stack-root)/hooks/ghc-install.sh
shell: bash

vanilla-channel:
strategy:
matrix:
Expand Down Expand Up @@ -93,3 +84,41 @@ jobs:

- if: runner.os == 'Windows'
run: ghcup run -m sh -- -c 'pacman --version'

config:
strategy:
matrix:
runs-on:
- ubuntu-latest
version:
- latest
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v4

- uses: ./
with:
stack-hook: true
version: ${{ matrix.version }}
config: |
# see https://github.com/haskell/ghcup-hs/blob/master/data/config.yaml
# for full documentation
url-source:
- StackSetupURL
verbose: true
- run: ghcup config
- run: ghcup debug-info
- run: ghcup tool-requirements
- run: ghcup list

- run: ghcup install stack latest --set
- run: ghcup whereis stack latest
- run: which stack
- run: stack --version

- name: Stack hook test
run: |
ghcup install stack latest
cat $(stack path --stack-root)/hooks/ghc-install.sh
shell: bash
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ jobs:
- uses: actions/checkout@v4
- uses: haskell/ghcup-setup@v1
with:
release-channels: |
GHCupURL
https://raw.githubusercontent.com/haskell/ghcup-metadata/refs/heads/master/ghcup-prereleases-0.0.8.yaml
config: |
# see https://github.com/haskell/ghcup-hs/blob/master/data/config.yaml
# for full documentation
url-source:
- GHCupURL
- prereleases
- run: |
ghcup install ghc --set ${{ matrix.ghc }}
ghcup install cabal --set ${{ matrix.cabal }}
Expand All @@ -59,7 +62,7 @@ jobs:
| Name | Description | Type | Default |
|------------------|-----------------------------------------------------------------|------------|------------|
| version | GHCup version to install | `string` | `latest` |
| release-channels | Set the release-channels | `string[]` | `GHCupURL` |
| config | Set ghcup config | `string[]` | `null` |
| stack-hook | Install the GHCup stack hook (GHCs are installed through ghcup) | `boolean` | `false` |

## Outputs
Expand Down
8 changes: 5 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ inputs:
description: GHCup version to install
default: latest
release-channels:
description: Set the release-channels
default: |
GHCupURL
description: Set the release-channels (deprecated, use 'config' instead)
default: ""
stack-hook:
description: Install the GHCup stack hook (GHCs are installed through ghcup)
default: false
config:
description: GHCup config (partial or full)
default: ""

outputs:
path:
Expand Down
Binary file modified ghcup/bun.lockb
Binary file not shown.
218 changes: 178 additions & 40 deletions ghcup/dist/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion ghcup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1",
"@actions/io": "^1.1.3",
"@actions/tool-cache": "^2.0.1"
"@actions/tool-cache": "^2.0.1",
"yaml": "^2.7.0"
}
}
7 changes: 6 additions & 1 deletion ghcup/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { main, getInputAsBool } from "./main.ts";
import core from "@actions/core";
import YAML from "yaml";

try {
main({
version: core.getInput("version"),
release_channels: core.getMultilineInput("release-channels"),
release_channels: core.getMultilineInput("release-channels") || undefined,
stack_hook: getInputAsBool("stack-hook"),
config:
(YAML.parse(core.getInput("config")) ??
JSON.parse(core.getInput("config"))) ||
undefined,
});
} catch (error) {
core.setFailed((error as Error).message);
Expand Down
24 changes: 17 additions & 7 deletions ghcup/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ export function getInputAsBool(

export type Opts = {
version: string;
release_channels: string[];
release_channels?: string[];
stack_hook: boolean;
config?: string;
};

export async function main(opts: Opts) {
Expand Down Expand Up @@ -173,10 +174,19 @@ export async function main(opts: Opts) {
installStackHook();
}

await exec.exec(ghcupPath, [
"config",
"set",
"url-source",
JSON.stringify(opts.release_channels),
]);
if (opts.config) {
await exec.exec(ghcupPath, ["config", "set", JSON.stringify(opts.config)]);
}

if (opts.release_channels && opts.release_channels.length > 0) {
core.warning(
"'release-channels' option is deprecated, use 'config' instead!",
);
await exec.exec(ghcupPath, [
"config",
"set",
"url-source",
JSON.stringify(opts.release_channels),
]);
}
}

0 comments on commit eb8eee7

Please sign in to comment.