Skip to content

Commit a4e1b39

Browse files
committed
build and install dagger from source
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
1 parent 7d447c2 commit a4e1b39

File tree

13 files changed

+152
-12
lines changed

13 files changed

+152
-12
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,23 @@ jobs:
8282
name: Check
8383
run: |
8484
dagger version
85+
86+
build-ref:
87+
runs-on: ubuntu-latest
88+
strategy:
89+
fail-fast: false
90+
matrix:
91+
ref:
92+
- refs/tags/v0.2.5
93+
- refs/pull/2288/head
94+
steps:
95+
-
96+
name: Checkout
97+
uses: actions/checkout@v2
98+
-
99+
name: Dagger
100+
uses: ./
101+
with:
102+
version: https://github.com/dagger/dagger.git#${{ matrix.ref }}
103+
cmds: do test
104+
workdir: ./test/ci

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ Following inputs can be used as `step.with` keys
8787
> do test
8888
> ```
8989

90-
| Name | Type | Default | Description |
91-
|------------------|--------|--------------|------------------------------------------------|
92-
| `version` | String | `latest` | Dagger version |
93-
| `cmds` | List | | List of Dagger commands |
94-
| `workdir` | String | `.` | Working directory (below repository root) |
95-
| `install-only` | Bool | `false` | Just install Dagger |
96-
| `cleanup` | Bool | `true` | Cleanup Dagger home folder at the end of a job |
90+
| Name | Type | Default | Description |
91+
|------------------|--------|--------------|----------------------------------------------------------------------------------------|
92+
| `version` | String | `latest` | Dagger version (e.g., `v0.2.7`, `latest`, `https://github.com/dagger/dagger.git#main`) |
93+
| `cmds` | List | | List of Dagger commands |
94+
| `workdir` | String | `.` | Working directory (below repository root) |
95+
| `install-only` | Bool | `false` | Just install Dagger |
96+
| `cleanup` | Bool | `true` | Cleanup Dagger home folder at the end of a job |
9797

9898
## Development
9999

__tests__/context.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
import {describe, expect, it} from '@jest/globals';
1+
import {describe, expect, jest, it} from '@jest/globals';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
24
import * as context from '../src/context';
35

6+
jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
7+
const tmpDir = path.join('/tmp/.dagger-jest').split(path.sep).join(path.posix.sep);
8+
if (!fs.existsSync(tmpDir)) {
9+
fs.mkdirSync(tmpDir, {recursive: true});
10+
}
11+
return tmpDir;
12+
});
13+
414
describe('getInputList', () => {
515
it('handles single line correctly', async () => {
616
await setInput('foo', 'bar');

__tests__/dagger.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import {describe, expect, it} from '@jest/globals';
22
import * as fs from 'fs';
33
import * as dagger from '../src/dagger';
44

5+
describe('build', () => {
6+
it.skip('valid', async () => {
7+
const daggerBin = await dagger.build('https://github.com/dagger/dagger.git#refs/pull/2161/head');
8+
expect(fs.existsSync(daggerBin)).toBe(true);
9+
}, 100000);
10+
});
11+
512
describe('install', () => {
613
it('acquires latest version of Dagger', async () => {
714
const daggerBin = await dagger.install('latest');

__tests__/git.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {describe, expect, it} from '@jest/globals';
2+
import * as git from '../src/git';
3+
4+
describe('git', () => {
5+
it('returns git remote ref', async () => {
6+
const ref: string = await git.getRemoteSha('https://github.com/dagger/dagger.git', 'refs/pull/2161/head');
7+
expect(ref).toEqual('aeb8ea3973a7815fff7cbd16f986811baa08ae2f');
8+
});
9+
});

__tests__/util.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {describe, expect, test} from '@jest/globals';
2+
import * as util from '../src/util';
3+
4+
describe('isValidUrl', () => {
5+
test.each([
6+
['https://github.com/dagger/dagger.git', true],
7+
['https://github.com/dagger/dagger.git#refs/pull/2161/head', true],
8+
['v0.2.7', false]
9+
])('given %p', async (url, expected) => {
10+
expect(util.isValidUrl(url)).toEqual(expected);
11+
});
12+
});

dist/index.js

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

dist/index.js.map

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

src/context.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
import fs from 'fs';
2+
import * as os from 'os';
3+
import path from 'path';
14
import * as core from '@actions/core';
25

6+
let _tmpDir: string;
7+
8+
export function tmpDir(): string {
9+
if (!_tmpDir) {
10+
_tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'dagger-')).split(path.sep).join(path.posix.sep);
11+
}
12+
return _tmpDir;
13+
}
14+
315
export interface Inputs {
416
version: string;
517
workdir: string;

src/dagger.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,46 @@
11
import * as os from 'os';
22
import * as path from 'path';
33
import * as util from 'util';
4+
import * as context from './context';
5+
import * as git from './git';
46
import * as core from '@actions/core';
7+
import * as exec from '@actions/exec';
58
import * as http from '@actions/http-client';
69
import * as tc from '@actions/tool-cache';
710

811
const s3URL = 'https://dl.dagger.io/dagger';
912
const osPlat: string = os.platform();
1013
const osArch: string = os.arch();
1114

15+
export async function build(inputBuildRef: string): Promise<string> {
16+
// eslint-disable-next-line prefer-const
17+
let [repo, ref] = inputBuildRef.split('#');
18+
if (ref.length == 0) {
19+
ref = 'main';
20+
}
21+
22+
const sha = await git.getRemoteSha(repo, ref);
23+
core.debug(`Remote ref ${sha} found`);
24+
25+
let toolPath: string;
26+
toolPath = tc.find('dagger', sha);
27+
if (!toolPath) {
28+
const outFolder = path.join(context.tmpDir(), 'out').split(path.sep).join(path.posix.sep);
29+
toolPath = await exec
30+
.getExecOutput('docker', ['buildx', 'build', '--build-arg', 'BUILDKIT_CONTEXT_KEEP_GIT_DIR=1', '--output', `type=local,dest=${outFolder}`, inputBuildRef], {
31+
ignoreReturnCode: true
32+
})
33+
.then(res => {
34+
if (res.stderr.length > 0 && res.exitCode != 0) {
35+
core.warning(res.stderr.trim());
36+
}
37+
return tc.cacheFile(`${outFolder}/bin/dagger`, osPlat == 'win32' ? 'dagger.exe' : 'dagger', 'dagger', sha);
38+
});
39+
}
40+
41+
return path.join(toolPath, osPlat == 'win32' ? 'dagger.exe' : 'dagger');
42+
}
43+
1244
export async function install(version: string): Promise<string> {
1345
version = await getVersionMapping(version);
1446
version = version.replace(/^v/, '');

0 commit comments

Comments
 (0)