Skip to content

Commit a40524d

Browse files
committed
ci: publish to jsr and setup release workflow
fix ci fix ci fix sdk version
1 parent 76f940f commit a40524d

File tree

7 files changed

+330
-31
lines changed

7 files changed

+330
-31
lines changed

.fluentci/src/dagger/jobs.ts

Lines changed: 97 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { dag, env, Directory, DirectoryID, File } from "../../deps.ts";
7+
import { buildRustFlags } from "./lib.ts";
78

89
export enum Job {
910
clippy = "clippy",
@@ -169,45 +170,110 @@ export async function test(
169170
* @param {string} packageName
170171
* @param {string} target
171172
* @param {string[]} options
172-
* @returns {string}
173+
* @returns {Promise<string>}
173174
*/
174-
export async function build(
175-
src: string | Directory | undefined = ".",
176-
packageName?: string,
177-
target = "x86_64-unknown-linux-gnu",
178-
options: string[] = []
179-
): Promise<Directory | string> {
175+
export const build = async (src = "."): Promise<string> => {
176+
const rustflags = buildRustFlags();
180177
const context = await getDirectory(src);
181178
const ctr = dag
182179
.pipeline(Job.build)
183180
.container()
184-
.from("rust:latest")
181+
.from("rust:1.76-bullseye")
182+
.withExec(["dpkg", "--add-architecture", "armhf"])
183+
.withExec(["dpkg", "--add-architecture", "arm64"])
184+
.withExec(["apt-get", "update"])
185+
.withExec([
186+
"apt-get",
187+
"install",
188+
"-y",
189+
"build-essential",
190+
"protobuf-compiler",
191+
])
192+
.withExec([
193+
"apt-get",
194+
"install",
195+
"-y",
196+
"-qq",
197+
"gcc-arm-linux-gnueabihf",
198+
"libc6-armhf-cross",
199+
"libc6-dev-armhf-cross",
200+
"gcc-aarch64-linux-gnu",
201+
"libc6-arm64-cross",
202+
"libc6-dev-arm64-cross",
203+
"libc6-armel-cross",
204+
"libc6-dev-armel-cross",
205+
"binutils-arm-linux-gnueabi",
206+
"gcc-arm-linux-gnueabi",
207+
"libncurses5-dev",
208+
"bison",
209+
"flex",
210+
"libssl-dev",
211+
"bc",
212+
"pkg-config",
213+
"libudev-dev",
214+
])
215+
.withExec(["mkdir", "-p", "/build/sysroot"])
185216
.withDirectory("/app", context, { exclude })
186217
.withWorkdir("/app")
187218
.withMountedCache("/app/target", dag.cacheVolume("target"))
188219
.withMountedCache("/root/cargo/registry", dag.cacheVolume("registry"))
189-
.withExec(
190-
env.has("PACKAGE_NAME") || packageName
191-
? [
192-
"cargo",
193-
"build",
194-
"--release",
195-
"-p",
196-
env.get("PACKAGE_NAME") || packageName!,
197-
"--target",
198-
target,
199-
...options,
200-
]
201-
: ["cargo", "build", "--release", "--target", target, ...options]
220+
.withMountedCache("/assets", dag.cacheVolume("gh-release-assets"))
221+
.withEnvVariable("RUSTFLAGS", rustflags)
222+
.withEnvVariable(
223+
"PKG_CONFIG_ALLOW_CROSS",
224+
env.get("TARGET") !== "x86_64-unknown-linux-gnu" ? "1" : "0"
202225
)
203-
.withExec(["cp", "-r", `/app/target/${target}`, "/"]);
204-
205-
const result = await ctr.stdout();
206-
207-
console.log(result);
208-
await ctr.directory(`/${target}`).export("./target");
209-
return ctr.directory(`/${target}`).id();
210-
}
226+
.withEnvVariable(
227+
"C_INCLUDE_PATH",
228+
env.get("TARGET") !== "x86_64-unknown-linux-gnu"
229+
? "/build/sysroot/usr/include"
230+
: "/usr/include"
231+
)
232+
.withEnvVariable("TAG", env.get("TAG") || "latest")
233+
.withEnvVariable("TARGET", env.get("TARGET") || "x86_64-unknown-linux-gnu")
234+
.withExec(["sh", "-c", "rustup target add $TARGET"])
235+
.withExec([
236+
"sh",
237+
"-c",
238+
"cargo build -p fluentci-engine --release --target $TARGET",
239+
])
240+
.withExec(["sh", "-c", "cp target/${TARGET}/release/fluentci-engine ."])
241+
.withExec([
242+
"sh",
243+
"-c",
244+
"tar czvf /assets/fluentci-engine_${TAG}_${TARGET}.tar.gz fluentci-engine",
245+
])
246+
.withExec([
247+
"sh",
248+
"-c",
249+
"shasum -a 256 /assets/fluentci-engine_${TAG}_${TARGET}.tar.gz > /assets/fluentci-engine_${TAG}_${TARGET}.tar.gz.sha256",
250+
])
251+
.withExec([
252+
"sh",
253+
"-c",
254+
"cp /assets/fluentci-engine_${TAG}_${TARGET}.tar.gz .",
255+
])
256+
.withExec([
257+
"sh",
258+
"-c",
259+
"cp /assets/fluentci-engine_${TAG}_${TARGET}.tar.gz.sha256 .",
260+
]);
261+
262+
const exe = await ctr.file(
263+
`/app/fluentci-engine_${env.get("TAG")}_${env.get("TARGET")}.tar.gz`
264+
);
265+
await exe.export(
266+
`./fluentci-engine_${env.get("TAG")}_${env.get("TARGET")}.tar.gz`
267+
);
268+
269+
const sha = await ctr.file(
270+
`/app/fluentci-engine_${env.get("TAG")}_${env.get("TARGET")}.tar.gz.sha256`
271+
);
272+
await sha.export(
273+
`./fluentci-engine_${env.get("TAG")}_${env.get("TARGET")}.tar.gz.sha256`
274+
);
275+
return ctr.stdout();
276+
};
211277

212278
/**
213279
* Run e2e tests
@@ -382,7 +448,8 @@ export async function typescriptE2e(
382448
export type JobExec =
383449
| ((src?: string | Directory | undefined) => Promise<Directory | string>)
384450
| ((src?: string | Directory | undefined) => Promise<File | string>)
385-
| ((src?: string | Directory | undefined) => Promise<string>);
451+
| ((src?: string | Directory | undefined) => Promise<string>)
452+
| ((src?: string) => Promise<string>);
386453

387454
export const runnableJobs: Record<Job, JobExec> = {
388455
[Job.clippy]: clippy,

.fluentci/src/dagger/lib.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { env } from "../../deps.ts";
2+
3+
export function buildRustFlags(): string {
4+
let rustflags = "";
5+
switch (env.get("TARGET")) {
6+
case "aarch64-unknown-linux-gnu":
7+
rustflags = `-C linker=aarch64-linux-gnu-gcc \
8+
-L/usr/aarch64-linux-gnu/lib \
9+
-L/build/sysroot/usr/lib/aarch64-linux-gnu \
10+
-L/build/sysroot/lib/aarch64-linux-gnu`;
11+
break;
12+
case "armv7-unknown-linux-gnueabihf":
13+
rustflags = `-C linker=arm-linux-gnueabihf-gcc \
14+
-L/usr/arm-linux-gnueabihf/lib \
15+
-L/build/sysroot/usr/lib/arm-linux-gnueabihf \
16+
-L/build/sysroot/lib/arm-linux-gnueabihf`;
17+
break;
18+
default:
19+
break;
20+
}
21+
return rustflags;
22+
}

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,17 @@ jobs:
2020
PACKAGE_NAME: fluentci-engine
2121
WORK_DIR: ./fixtures
2222
DAGGER_CLOUD_TOKEN: ${{ secrets.DAGGER_CLOUD_TOKEN }}
23+
publish:
24+
needs: tests
25+
runs-on: ubuntu-latest
26+
permissions:
27+
contents: read
28+
id-token: write
29+
steps:
30+
- uses: actions/checkout@v4
31+
- uses: denoland/setup-deno@v1
32+
with:
33+
deno-version: v1.41
34+
- name: Publish package
35+
run: deno publish --allow-slow-types
36+
working-directory: ./sdk/typescript

.github/workflows/release-for-mac.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
on:
2+
release:
3+
types: [created]
4+
5+
jobs:
6+
release:
7+
name: release x86_64-apple-darwin
8+
runs-on: macos-latest
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
target:
13+
- x86_64-apple-darwin
14+
- aarch64-apple-darwin
15+
16+
steps:
17+
- name: Setup Fluent CI CLI
18+
uses: fluentci-io/setup-fluentci@v4
19+
- name: Installing needed dependencies
20+
run: brew install protobuf
21+
- name: Installing Rust toolchain
22+
uses: actions-rs/toolchain@v1
23+
with:
24+
toolchain: stable
25+
target: ${{ matrix.target }}
26+
override: true
27+
- name: Checking out sources
28+
uses: actions/checkout@v1
29+
- name: Running cargo build
30+
uses: actions-rs/cargo@v1
31+
with:
32+
command: build
33+
toolchain: stable
34+
args: --release --target ${{ matrix.target }}
35+
- name: Install aarch64-apple-darwin toolchain
36+
if: matrix.target == 'aarch64-apple-darwin'
37+
run: rustup target add aarch64-apple-darwin
38+
- name: Set env
39+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
40+
- name: Packaging final binary
41+
shell: bash
42+
run: |
43+
cd target/${{ matrix.target }}/release
44+
tar czvf ../../../fluentci-engine_${{ env.RELEASE_VERSION }}_${{ matrix.target }}.tar.gz fluentci-engine
45+
shasum -a 256 ../../../fluentci-engine_${{ env.RELEASE_VERSION }}_${{ matrix.target }}.tar.gz > ../../../fluentci-engine_${{ env.RELEASE_VERSION }}_${{ matrix.target }}.tar.gz.sha256
46+
cd ../../../ && rm -rf target
47+
- name: Upload release assets
48+
run: |
49+
for ext in tar.gz tar.gz.sha256; do
50+
export FILE=fluentci-engine_${{ env.RELEASE_VERSION }}_${{ matrix.target }}.$ext
51+
fluentci run github_pipeline release_upload
52+
done
53+
env:
54+
TAG: ${{ env.RELEASE_VERSION }}
55+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: release
2+
on:
3+
release:
4+
types: [created]
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
target:
12+
- aarch64-unknown-linux-gnu
13+
- armv7-unknown-linux-gnueabihf
14+
- x86_64-unknown-linux-gnu
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: fluentci-io/setup-fluentci@v4
18+
- name: Set env
19+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
20+
- name: Build
21+
run: fluentci run . build
22+
env:
23+
TAG: ${{ env.RELEASE_VERSION }}
24+
TARGET: ${{ matrix.target }}
25+
- name: Upload release assets
26+
run: |
27+
for ext in tar.gz tar.gz.sha256; do
28+
export FILE=/assets/fluentci-engine_${{ env.RELEASE_VERSION }}_${{ matrix.target }}.$ext
29+
fluentci run github_pipeline release_upload
30+
done
31+
env:
32+
TAG: ${{ env.RELEASE_VERSION }}
33+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

sdk/typescript/README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# FluentCI TypeScript
2+
3+
![deno compatibility](https://shield.deno.dev/deno/^1.41)
4+
[![](https://jsr.io/badges/@fluentci/sdk)](https://jsr.io/@fluentci/sdk)
5+
[![ci](https://github.com/fluentci-io/fluentci-engine/actions/workflows/ci.yml/badge.svg)](https://github.com/fluentci-io/fluentci-engine/actions/workflows/ci.yml)
6+
[![discord](https://img.shields.io/discord/1132020671262773358?label=discord&logo=discord&color=5865F2)](https://discord.gg/V4U6dPskKc)
7+
8+
The FluentCI TypeScript SDK contains everything you need to develop CI/CD pipelines in TypeScript or Javascript, and run them on [Nix](https://nixos.org) environments.
9+
10+
## Quick Start
11+
12+
Clone the [FluentCI Engine](https://github.com/fluentci-io/fluentci-engine) repository and start the engine at the fixtures directory:
13+
14+
```bash
15+
git clone https://github.com/fluentci-io/fluentci-engine
16+
cd fluentci-engine/fixtures
17+
# you can get this binary from the releases page
18+
# start the engine
19+
fluentci-engine
20+
```
21+
22+
Now you can save the following code to a file called `main.ts` and run it with `deno run -A main.ts`:
23+
24+
```typescript
25+
import { dag } from "jsr:@fluentci/sdk";
26+
27+
async function main() {
28+
Deno.env.set("FLUENTCI_SESSION_PORT", "6880");
29+
Deno.env.set("FLUENTCI_SESSION_TOKEN", "token");
30+
31+
const demo = await dag
32+
.pipeline("demo")
33+
.withWorkdir("./")
34+
.withExec(["echo", "hello"])
35+
.withExec(["echo", "hello world"])
36+
.withExec(["echo", "hello again"])
37+
.stdout();
38+
39+
console.log(demo);
40+
41+
42+
const nix = await dag
43+
.pipeline("nix-demo")
44+
.nix()
45+
.withWorkdir("./nix-demo")
46+
.withExec(["nix", "--version"])
47+
.withExec(["which", "deno"])
48+
.stdout();
49+
50+
console.log(nix);
51+
52+
const pkgx = await dag
53+
.pipeline("pkgx-demo")
54+
.pkgx()
55+
.withWorkdir("./pkgx-demo")
56+
.withExec(["pkgx", "--version"])
57+
.withExec(["which", "deno"])
58+
.stdout();
59+
60+
console.log(pkgx);
61+
62+
const git = await dag
63+
.git("https://github.com/tsirysndr/me")
64+
.branch("main")
65+
.tree()
66+
.withExec(["pwd"])
67+
.stdout();
68+
console.log(git);
69+
70+
const gitEntries = await dag
71+
.git("https://github.com/tsirysndr/me")
72+
.branch("main")
73+
.tree()
74+
.entries();
75+
76+
console.log(gitEntries);
77+
78+
const dir = await dag.directory(".").entries();
79+
80+
console.log(dir);
81+
82+
83+
const devbox = await dag
84+
.pipeline("devbox-demo")
85+
.devbox()
86+
.withWorkdir("./devbox-demo")
87+
.withExec(["devbox", "version"])
88+
.withExec(["which", "jq"])
89+
.stdout();
90+
91+
console.log(devbox);
92+
93+
const flox = await dag
94+
.pipeline("flox-demo")
95+
.flox()
96+
.withWorkdir("./flox-demo")
97+
.withExec(["flox", "--version"])
98+
.withExec(["which", "jq"])
99+
.stdout();
100+
101+
console.log(flox);
102+
}
103+
104+
// Learn more at https://deno.land/manual/examples/module_metadata#concepts
105+
if (import.meta.main) {
106+
await main();
107+
}
108+
```

0 commit comments

Comments
 (0)