From 2973b46585b5892e7938a31f26c0d81d7f7993ad Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Fri, 23 Feb 2024 18:45:01 +0000 Subject: [PATCH] configure nix flakes --- .fluentci/src/dagger/jobs.ts | 44 +++++-- .github/workflows/ci.yml | 2 +- .github/workflows/codesee-arch-diagram.yml | 23 ---- .github/workflows/flakestry-publish.yml | 22 ++++ .github/workflows/release.yml | 37 ++++++ README.md | 5 +- flake.lock | 139 +++++++++++++++++++++ flake.nix | 45 +++++++ 8 files changed, 280 insertions(+), 37 deletions(-) delete mode 100644 .github/workflows/codesee-arch-diagram.yml create mode 100644 .github/workflows/flakestry-publish.yml create mode 100644 .github/workflows/release.yml create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.fluentci/src/dagger/jobs.ts b/.fluentci/src/dagger/jobs.ts index 1c067ea..75ab339 100644 --- a/.fluentci/src/dagger/jobs.ts +++ b/.fluentci/src/dagger/jobs.ts @@ -157,9 +157,10 @@ export async function compile( let command = [ "deno", "compile", + "--unstable", "-A", "--output", - output, + "pocketenv", "--target", Deno.env.get("TARGET") || target, file, @@ -180,26 +181,45 @@ export async function compile( .withExec([ "tar", "czvf", - `/assets/${output}_${Deno.env.get("TAG") || ""}_${ + `/assets/pocketenv_${Deno.env.get("TAG") || ""}_${ Deno.env.get("TARGET") || target }.tar.gz`, - output, + "pocketenv", ]) .withExec([ "sh", "-c", - `shasum -a 256 /assets/${output}_${Deno.env.get("TAG") || ""}_${ + `shasum -a 256 /assets/pocketenv_${Deno.env.get("TAG") || ""}_${ Deno.env.get("TARGET") || target - }.tar.gz > /assets/${output}_${ - Deno.env.get("TAG") || "" - }_${Deno.env.get("TARGET" || target)}.tar.gz.sha256`, - ]); - - const exe = await ctr.file(`/app/${output}`); - exe.export(`./${output}`); + }.tar.gz > /assets/pocketenv_${Deno.env.get("TAG") || ""}_${ + Deno.env.get("TARGET") || target + }.tar.gz.sha256`, + ]) + .withExec(["sh", "-c", "cp /assets/* /app"]); + + const sha256 = await ctr.file( + `/app/pocketenv_${Deno.env.get("TAG") || ""}_${ + Deno.env.get("TARGET") || target + }.tar.gz.sha256` + ); + const tar = await ctr.file( + `/app/pocketenv_${Deno.env.get("TAG") || ""}_${ + Deno.env.get("TARGET") || target + }.tar.gz` + ); + tar.export( + `./pocketenv_${Deno.env.get("TAG") || ""}_${ + Deno.env.get("TARGET") || target + }.tar.gz` + ); + sha256.export( + `./pocketenv_${Deno.env.get("TAG") || ""}_${ + Deno.env.get("TARGET") || target + }.tar.gz.sha256` + ); await ctr.stdout(); - id = await exe.id(); + id = await tar.id(); }); return id; diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76d9742..85b1717 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Setup Fluent CI - uses: fluentci-io/setup-fluentci@v3 + uses: fluentci-io/setup-fluentci@v4 - name: Run Dagger Pipelines run: fluentci run deno_pipeline fmt lint env: diff --git a/.github/workflows/codesee-arch-diagram.yml b/.github/workflows/codesee-arch-diagram.yml deleted file mode 100644 index 806d41d..0000000 --- a/.github/workflows/codesee-arch-diagram.yml +++ /dev/null @@ -1,23 +0,0 @@ -# This workflow was added by CodeSee. Learn more at https://codesee.io/ -# This is v2.0 of this workflow file -on: - push: - branches: - - main - pull_request_target: - types: [opened, synchronize, reopened] - -name: CodeSee - -permissions: read-all - -jobs: - codesee: - runs-on: ubuntu-latest - continue-on-error: true - name: Analyze the repo with CodeSee - steps: - - uses: Codesee-io/codesee-action@v2 - with: - codesee-token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }} - codesee-url: https://app.codesee.io diff --git a/.github/workflows/flakestry-publish.yml b/.github/workflows/flakestry-publish.yml new file mode 100644 index 0000000..b025062 --- /dev/null +++ b/.github/workflows/flakestry-publish.yml @@ -0,0 +1,22 @@ +name: "Publish a flake to flakestry" +on: + push: + tags: + - "v?[0-9]+.[0-9]+.[0-9]+" + - "v?[0-9]+.[0-9]+" + workflow_dispatch: + inputs: + tag: + description: "The existing tag to publish" + type: "string" + required: true +jobs: + publish-flake: + runs-on: ubuntu-latest + permissions: + id-token: "write" + contents: "read" + steps: + - uses: tsirysndr/flakestry-publish@main + with: + version: "${{ inputs.tag || github.ref_name }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..08ed634 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: release +on: + release: + types: [created] + +jobs: + build: + name: release + runs-on: ubuntu-latest + strategy: + matrix: + target: + - x86_64-unknown-linux-gnu + - x86_64-apple-darwin + - aarch64-apple-darwin + steps: + - uses: actions/checkout@v3 + - name: Setup Fluent CI + uses: fluentci-io/setup-fluentci@v4 + - name: Set env + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + - name: Build + run: fluentci run . compile + env: + TAG: ${{ env.RELEASE_VERSION }} + TARGET: ${{ matrix.target }} + DAGGER_CLOUD_TOKEN: ${{ secrets.DAGGER_CLOUD_TOKEN }} + - name: Upload release assets + run: | + for ext in tar.gz tar.gz.sha256; do + export FILE=/app/pocketenv_${{ env.RELEASE_VERSION }}_${{ matrix.target }}.$ext + fluentci run github_pipeline release_upload + done + env: + TAG: ${{ env.RELEASE_VERSION }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DAGGER_CLOUD_TOKEN: ${{ secrets.DAGGER_CLOUD_TOKEN }} diff --git a/README.md b/README.md index 43fab2d..92820ca 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,10 @@ # Pocketenv -[![CodeSee](https://codesee-docs.s3.amazonaws.com/badge.svg?)](https://app.codesee.io/maps/public/85353fa0-c4dd-11ee-95ac-897807a2630c) +[![FlakeHub](https://img.shields.io/endpoint?url=https://flakehub.com/f/pocketenv-io/pocketenv/badge)](https://flakehub.com/flake/pocketenv-io/pocketenv) +[![deno module](https://shield.deno.dev/x/pocketenv)](https://deno.land/x/pocketenv) +![deno compatibility](https://shield.deno.dev/deno/^1.37) +[![flakestry.dev](https://flakestry.dev/api/badge/flake/github/pocketenv-io/pocketenv)](https://flakestry.dev/flake/github/pocketenv-io/pocketenv) Pocketenv is a simple and lightweight tool to manage development workspace environments. It allows you to define and manage workspaces for your projects, and easily switch between them. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5e41ba8 --- /dev/null +++ b/flake.lock @@ -0,0 +1,139 @@ +{ + "nodes": { + "deno2nix": { + "inputs": { + "devshell": "devshell", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1708712887, + "narHash": "sha256-gCnFHxA6TqMzyO3E2Jr7ElMpTwLdme7wPgNZnHY1CUk=", + "owner": "tsirysndr", + "repo": "deno2nix", + "rev": "59b13ec521e8e5a1e0c8b15ddaed6a1e7ae75237", + "type": "github" + }, + "original": { + "owner": "tsirysndr", + "repo": "deno2nix", + "type": "github" + } + }, + "devshell": { + "inputs": { + "flake-utils": [ + "deno2nix", + "flake-utils" + ], + "nixpkgs": [ + "deno2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1667210711, + "narHash": "sha256-IoErjXZAkzYWHEpQqwu/DeRNJGFdR7X2OGbkhMqMrpw=", + "owner": "numtide", + "repo": "devshell", + "rev": "96a9dd12b8a447840cc246e17a47b81a4268bba7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1668681692, + "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1708564076, + "narHash": "sha256-KKkqoxlgx9n3nwST7O2kM8tliDOijiSSNaWuSkiozdQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "98b00b6947a9214381112bdb6f89c25498db4959", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "deno2nix": "deno2nix", + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..2059359 --- /dev/null +++ b/flake.nix @@ -0,0 +1,45 @@ +{ + description = "Manage your development environment with ease ✨"; + + inputs = { + utils.url = "github:numtide/flake-utils"; + deno2nix = { + url = "github:tsirysndr/deno2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, utils, deno2nix }: + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ deno2nix.overlays.default ]; + }; + in + rec { + + apps.default = utils.lib.mkApp { + drv = packages.default; + }; + + packages.default = pkgs.deno2nix.mkExecutable { + pname = "pocketenv"; + version = "0.1.0"; + + src = ./.; + lockfile = "./deno.lock"; + config = "./deno.json"; + entrypoint = "./main.ts"; + allow = { + all = true; + }; + }; + + devShell = pkgs.mkShell { + buildInputs = with pkgs; [ + deno + ]; + }; + }); +} \ No newline at end of file