Skip to content

Commit 51e0d43

Browse files
committed
Initial version of GitHub action
1 parent 66862b6 commit 51e0d43

File tree

8 files changed

+268
-0
lines changed

8 files changed

+268
-0
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: [thomashoneyman]

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Ignore dotfiles except for explicit exceptions
2+
/.*
3+
!/.gitignore
4+
!/.github
5+
6+
# Dependencies
7+
node_modules

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Setup PureScript Action
2+
3+
A GitHub Action which sets up a PureScript toolchain for CI. Contains the following tools:
4+
5+
- The [PureScript compiler](https://github.com/purescript/purescript)
6+
- The [Spago package manager and build tool](https://github.com/purescript/spago)
7+
8+
## Usage
9+
10+
See the [action.yml](action.yml) file for all possible inputs and outputs.
11+
12+
### Basic
13+
14+
Get the latest versions of PureScript and Spago in the environment:
15+
16+
```yaml
17+
steps:
18+
- uses: actions/checkout@v2
19+
- uses: thomashoneyman/setup-purescript@master
20+
- run: spago build
21+
```
22+
23+
### Use Specific Versions
24+
25+
Use specific versions of PureScript and/or Spago by supplying a valid tag in their respective GitHub repositories:
26+
27+
```yaml
28+
steps:
29+
- uses: actions/checkout@v2
30+
- uses: thomashoneyman/setup-purescript@master
31+
with:
32+
purescript-version: "0.13.8"
33+
spago-version: "0.15.3"
34+
- run: spago build
35+
```

action.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: "Set up a PureScript toolchain"
2+
description: "Install a PureScript toolchain and add it to the PATH"
3+
author: "Thomas Honeyman <[email protected]>"
4+
inputs:
5+
purescript-version:
6+
description: "The compiler version to install. Examples: latest, 0.13.8"
7+
default: "latest"
8+
spago-version:
9+
description: "The Spago version to install. Examples: latest, 0.15.3"
10+
default: "latest"
11+
runs:
12+
using: "node12"
13+
main: "dist/index.js"

dist/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
const core = require("@actions/core");
2+
const tc = require("@actions/tool-cache");
3+
const semver = require("semver");
4+
5+
const PureScript = "PureScript";
6+
const Spago = "Spago";
7+
8+
const toolName = (tool) => {
9+
if (tool === PureScript) return "purs";
10+
if (tool === Spago) return "spago";
11+
};
12+
13+
const toolRepository = (tool) => {
14+
if (tool === PureScript) return "purescript/purescript";
15+
if (tool === Spago) return "purescript/spago";
16+
};
17+
18+
const toolVersionKey = (tool) => {
19+
if (tool === PureScript) return "purescript-version";
20+
if (tool === Spago) return "spago-version";
21+
};
22+
23+
const toolLatestTag = (tool) => {
24+
// TODO
25+
// Get the latest tag automatically:
26+
// TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest))
27+
if (tool === PureScript) return "0.13.8";
28+
if (tool === Spago) return "0.15.3";
29+
};
30+
31+
const toolVersion = (tool) => {
32+
const key = toolVersionKey(tool);
33+
const input = core.getInput(tool);
34+
if (input) {
35+
if (semver.valid(input)) {
36+
return input;
37+
} else {
38+
core.setFailed(`${input} is not valid for ${key}.`);
39+
}
40+
} else {
41+
return toolLatestTag(tool);
42+
}
43+
};
44+
45+
const Windows = "Windows";
46+
const Mac = "Mac";
47+
const Linux = "Linux";
48+
49+
const parsePlatform = (platform) => {
50+
if (platform === "win32") return Windows;
51+
if (platform === "darwin") return Mac;
52+
return Linux;
53+
};
54+
55+
const tarballName = (tool, platform) => {
56+
if (tool === PureScript) {
57+
if (platform === Windows) return "win64";
58+
if (platform === Mac) return "macos";
59+
if (platform === Linux) return "linux64";
60+
} else if (tool === Spago) {
61+
if (platform === Windows) return "windows";
62+
if (platform === Mac) return "osx";
63+
if (platform === Linux) return "linux";
64+
}
65+
};
66+
67+
const downloadTool = async (tool) => {
68+
const version = toolVersion(tool);
69+
const name = toolName(tool);
70+
71+
// If the tool has previously been downloaded at the provided version, then we
72+
// can simply add it to the PATH
73+
const cached = tc.find(name, version);
74+
if (cached) {
75+
core.addPath(cached);
76+
console.log(`Found cached version of ${name}, adding to PATH`);
77+
return;
78+
}
79+
80+
const platform = parsePlatform(process.platform);
81+
const tarball = tarballName(tool, platform);
82+
const repo = toolRepository(tool);
83+
84+
const downloadPath = await tc.downloadTool(
85+
`https://github.com/${repo}/releases/download/${version}/${tarball}.tar.gz`
86+
);
87+
88+
const extracted = await tc.extractTar(downloadPath);
89+
90+
switch (tool) {
91+
case PureScript:
92+
const purescriptPath = await tc.cacheDir(extracted, name, version);
93+
core.addPath(purescriptPath);
94+
return;
95+
96+
case Spago:
97+
let spagoPath = await tc.cacheFile(extracted, name, name, version);
98+
core.addPath(spagoPath);
99+
return;
100+
}
101+
};
102+
103+
const run = async () => {
104+
await downloadTool(PureScript);
105+
await downloadTool(Spago);
106+
};
107+
108+
run();

package-lock.json

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "setup-purescript",
3+
"version": "0.0.0",
4+
"description": "Set up a PureScript toolchain in GitHub Actions",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "ncc build index.js --minify",
8+
"test": "jest"
9+
},
10+
"keywords": [
11+
"github",
12+
"actions",
13+
"purescript",
14+
"spago"
15+
],
16+
"author": "Thomas Honeyman",
17+
"license": "MIT",
18+
"dependencies": {
19+
"@actions/core": "^1.2.4",
20+
"@actions/tool-cache": "^1.6.0",
21+
"semver": "^7.3.2"
22+
},
23+
"devDependencies": {
24+
"@zeit/ncc": "^0.22.3"
25+
}
26+
}

0 commit comments

Comments
 (0)