Skip to content

Commit

Permalink
fix(cli): fix executePath on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mildronize committed May 6, 2024
1 parent e6147a0 commit 933d15e
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 63 deletions.
163 changes: 104 additions & 59 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ env:

jobs:
get-matrix:
runs-on: ubuntu-latest
runs-on: windows-latest
outputs:
matrix: ${{ steps.deploy-matrix.outputs.matrix }}
deployable_matrix: ${{ steps.deploy-matrix.outputs.deployable_matrix }}
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
Expand All @@ -41,61 +42,105 @@ jobs:
- run: pnpm install
- name: Export the matrix for testing
id: deploy-matrix
run: pnpm exec nx run @infra/azure-functions:github-actions

build:
runs-on: ${{ matrix.os }}
needs: get-matrix
strategy:
matrix:
include: ${{fromJson(needs.get-matrix.outputs.matrix)}}

steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1

- name: Use Node.js ${{ matrix.version }}
if: matrix.runtime == 'node'
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.version }}

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: ${{ env.pnpm_version }}
- run: pnpm install

- run: pnpm build

- name: pnpm install again for ensure the cli is available
run: pnpm install

- name: Build the project
run: pnpm exec nx run @examples/with-${{ matrix.runtime }}:build
env:
DEBUG: ${{ env.debug_identifier }}

- name: Azure Login
uses: azure/login@v2
if: matrix.is_deployable == true
with:
creds: ${{ secrets.AZURE_CREDENTIALS_E2E_TESTS }}

- name: Deploy to Azure Functions
uses: Azure/functions-action@v1
if: matrix.is_deployable == true
with:
app-name: nmt-e2e-${{ matrix.target }}-${{ secrets[matrix.resource_identifier_key] }}
package: examples/with-${{ matrix.runtime }}/.nmt/dist

- name: Wait for the deployment to finish
if: matrix.is_deployable == true
run: sleep 15

- name: Run E2E tests
if: matrix.is_deployable == true
run: pnpm exec nx run @infra/azure-functions:test
env:
AZURE_FUNCTIONS_URL: https://nmt-e2e-${{ matrix.target }}-${{ secrets[matrix.resource_identifier_key] }}.azurewebsites.net
AZURE_FUNCTIONS_API_KEY: ${{ secrets.AZURE_FUNCTIONS_HOST_KEY }}
# run: pnpm exec nx run @infra/azure-functions:github-actions
run: pnpm exec nx run @infra/azure-functions:test-os


# darwin or linux or

# build:
# runs-on: ${{ matrix.os }}
# needs: get-matrix
# strategy:
# matrix:
# include: ${{fromJson(needs.get-matrix.outputs.matrix)}}

# steps:
# - uses: actions/checkout@v4
# - uses: oven-sh/setup-bun@v1

# - name: Use Node.js ${{ matrix.version }}
# if: matrix.runtime == 'node'
# uses: actions/setup-node@v3
# with:
# node-version: ${{ matrix.version }}

# - uses: pnpm/action-setup@v2
# name: Install pnpm
# with:
# version: ${{ env.pnpm_version }}
# - run: pnpm install

# - run: pnpm build

# - name: pnpm install again for ensure the cli is available
# run: pnpm install

# - name: Build the project
# run: pnpm exec nx run @examples/with-${{ matrix.runtime }}:build
# env:
# DEBUG: ${{ env.debug_identifier }}

# - name: Upload Artifact
# uses: actions/upload-artifact@v4
# with:
# name: ${{ matrix.resource_identifier_key }}
# path: examples/with-${{ matrix.runtime }}/.nmt/dist
# retention-days: 1

# - name: Azure Login
# uses: azure/login@v2
# if: matrix.is_deployable == true
# with:
# creds: ${{ secrets.AZURE_CREDENTIALS_E2E_TESTS }}

# - name: Deploy to Azure Functions
# uses: Azure/functions-action@v1
# if: matrix.is_deployable == true
# with:
# app-name: nmt-e2e-${{ matrix.target }}-${{ secrets[matrix.resource_identifier_key] }}
# package: examples/with-${{ matrix.runtime }}/.nmt/dist

# # - name: Wait for the deployment to finish
# # if: matrix.is_deployable == true
# # run: sleep 15

# # - name: Run E2E tests
# # if: matrix.is_deployable == true
# # run: pnpm exec nx run @infra/azure-functions:test
# # env:
# # AZURE_FUNCTIONS_URL: https://nmt-e2e-${{ matrix.target }}-${{ secrets[matrix.resource_identifier_key] }}.azurewebsites.net
# # AZURE_FUNCTIONS_API_KEY: ${{ secrets.AZURE_FUNCTIONS_HOST_KEY }}

# e2e:
# if: always()
# runs-on: ubuntu-latest
# needs:
# - build
# - get-matrix
# timeout-minutes: 10
# strategy:
# fail-fast: false
# matrix:
# include: ${{fromJson(needs.get-matrix.outputs.deployable_matrix)}}

# steps:
# - uses: actions/checkout@v4
# - uses: oven-sh/setup-bun@v1

# - name: Use Node.js ${{ env.node_version }}
# uses: actions/setup-node@v4
# with:
# node-version: ${{ env.node_version }}

# - uses: pnpm/action-setup@v3
# name: Install pnpm
# with:
# version: ${{ env.pnpm_version }}
# - run: pnpm install

# - name: Run E2E tests
# run: pnpm exec nx run @infra/azure-functions:test
# env:
# AZURE_FUNCTIONS_URL: https://nmt-e2e-${{ matrix.target }}-${{ secrets[matrix.resource_identifier_key] }}.azurewebsites.net
# AZURE_FUNCTIONS_API_KEY: ${{ secrets.AZURE_FUNCTIONS_HOST_KEY }}
1 change: 1 addition & 0 deletions infra/azure-functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"module": "src/main.ts",
"type": "module",
"scripts": {
"test-os": "tsx src/test-os.ts",
"apply": "bun run src/main.ts",
"plan": "PLAN_MODE=true bun run src/main.ts",
"test": "bun test",
Expand Down
7 changes: 5 additions & 2 deletions infra/azure-functions/src/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { test, expect } from 'bun:test';
import supertest from 'supertest';
// import supertest from 'supertest';

const url = process.env.AZURE_FUNCTIONS_URL;
const apiKey = process.env.AZURE_FUNCTIONS_API_KEY;
if (!url) throw new Error('AZURE_FUNCTIONS_URL not set');
if (!apiKey) throw new Error('AZURE_FUNCTIONS_API_KEY not set');

test('e2e', async () => {
const response = await supertest(url).get(`/api/SimpleHttpTrigger?code=${apiKey}`);
// const response = await supertest(url).get(`/api/SimpleHttpTrigger?code=${apiKey}`);
const response = await fetch(new URL(`/api/SimpleHttpTrigger?code=${apiKey}`, url).toString(), {
method: 'GET',
});
expect(response.status).toBe(200);
});
3 changes: 3 additions & 0 deletions infra/azure-functions/src/test-os.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
console.log('the current platform is ', process.platform);
console.log('the current architecture is ', process.arch);
console.log('the current version is ', process.version);
9 changes: 8 additions & 1 deletion packages/main/src/command/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,14 @@ export async function buildExecutable(options: NammathamConfigs, result: BuildNo
throw new Error(`Conflict target build runtime: ${targetOptions.runtime} with ${options.runtime}`);
}
const targetString = `${targetOptions.runtime}-${targetOptions.platform}-${targetOptions.arch}`;
const pkgArgs = [result.filePath, '--target', targetString, '--output', path.join(result.distDirectory, 'main')];
const executablePath = targetOptions.platform === 'win' ? 'main.exe' : 'main';
const pkgArgs = [
result.filePath,
'--target',
targetString,
'--output',
path.join(result.distDirectory, executablePath),
];
debug?.(`Building executable using pkg with args: ${pkgArgs.join(' ')}`);
await pkgExec(pkgArgs);
debug?.(`Executable built completed`);
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/command/config/config-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function constructHostConfig(config: NammathamConfigs): string {
{
customHandler: {
description: {
defaultExecutablePath: 'main',
defaultExecutablePath: config.buildOption?.target?.platform === 'win' ? 'main.exe' : 'main',
},
enableForwardingHttpRequest: true,
},
Expand Down

0 comments on commit 933d15e

Please sign in to comment.