diff --git a/.github/workflows/e2e-backup.yml b/.github/workflows/e2e-backup.yml new file mode 100644 index 0000000..cb8cacc --- /dev/null +++ b/.github/workflows/e2e-backup.yml @@ -0,0 +1,146 @@ +name: 'E2E Tests (Backup)' + +on: + workflow_dispatch: + # push: + # branches: [v3.x-bundle] + # paths-ignore: + # - '**/*.md' + # pull_request: + # branches: [ main ] + # paths-ignore: + # - '**/*.md' + +env: + pnpm_version: 8 + node_version: 20 + debug_identifier: nammatham:* + + RESOURCE_IDENTIFIER_NODE18_LINUX_X64: ${{ secrets.RESOURCE_IDENTIFIER_NODE18_LINUX_X64 }} + RESOURCE_IDENTIFIER_NODE18_WIN_X64: ${{ secrets.RESOURCE_IDENTIFIER_NODE18_WIN_X64 }} + +jobs: + get-matrix: + runs-on: ubuntu-latest + timeout-minutes: 4 + 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 + + - 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: 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 + timeout-minutes: 10 + 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@v4 + with: + node-version: ${{ matrix.version }} + + - uses: pnpm/action-setup@v3 + 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 + + deploy: + runs-on: ubuntu-latest + needs: + - build + - get-matrix + timeout-minutes: 10 + strategy: + matrix: + include: ${{fromJson(needs.get-matrix.outputs.deployable_matrix)}} + + steps: + - name: Azure Login + uses: azure/login@v2 + with: + creds: ${{ secrets.AZURE_CREDENTIALS_E2E_TESTS }} + + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: ${{ matrix.resource_identifier_key }} + path: examples/with-${{ matrix.runtime }}/.nmt/dist + + - name: Deploy to Azure Functions + uses: Azure/functions-action@v1 + with: + app-name: nmt-e2e-${{ matrix.target }}-${{ secrets[matrix.resource_identifier_key] }} + package: . + + e2e: + runs-on: ubuntu-latest + needs: + - build + - deploy + - get-matrix + timeout-minutes: 10 + strategy: + 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 }} diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 6ee6bd7..15290ba 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -10,20 +10,21 @@ on: # paths-ignore: # - '**/*.md' + env: pnpm_version: 8 node_version: 20 debug_identifier: nammatham:* RESOURCE_IDENTIFIER_NODE18_LINUX_X64: ${{ secrets.RESOURCE_IDENTIFIER_NODE18_LINUX_X64 }} + RESOURCE_IDENTIFIER_NODE18_WIN_X64: ${{ secrets.RESOURCE_IDENTIFIER_NODE18_WIN_X64 }} + jobs: get-matrix: runs-on: ubuntu-latest - timeout-minutes: 4 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 @@ -45,7 +46,6 @@ jobs: build: runs-on: ${{ matrix.os }} needs: get-matrix - timeout-minutes: 10 strategy: matrix: include: ${{fromJson(needs.get-matrix.outputs.matrix)}} @@ -76,61 +76,26 @@ jobs: 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 - - e2e: - runs-on: ubuntu-latest - needs: - - build - - get-matrix - timeout-minutes: 10 - strategy: - matrix: - include: ${{fromJson(needs.get-matrix.outputs.deployable_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 - - name: Azure Login uses: azure/login@v2 + if: matrix.is_deployable == true with: creds: ${{ secrets.AZURE_CREDENTIALS_E2E_TESTS }} - - name: Download Artifact - uses: actions/download-artifact@v4 - with: - name: ${{ matrix.resource_identifier_key }} - path: examples/with-${{ matrix.runtime }}/.nmt/dist - - 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: . + 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 }} + AZURE_FUNCTIONS_API_KEY: ${{ secrets.AZURE_FUNCTIONS_HOST_KEY }} \ No newline at end of file diff --git a/examples/with-node/nammatham.config.mjs b/examples/with-node/nammatham.config.mjs index 5b36314..674b144 100644 --- a/examples/with-node/nammatham.config.mjs +++ b/examples/with-node/nammatham.config.mjs @@ -3,6 +3,13 @@ /** @type {import('nammatham').NammathamConfigs} */ const nammathamConfig = { runtime: 'node', + buildOption: { + target: { + arch: 'x64', + platform: 'linux', + runtime: 'node18', + }, + }, hostConfig: { version: '2.0', extensionBundle: { @@ -28,9 +35,9 @@ const nammathamConfig = { excludedTypes: 'Request', }, }, - // logLevel: { - // default: 'Trace', - // }, + logLevel: { + default: 'Trace', + }, }, }, }; diff --git a/infra/azure-functions/src/e2e.test.ts b/infra/azure-functions/src/e2e.test.ts index 0fb62ab..f02eacc 100644 --- a/infra/azure-functions/src/e2e.test.ts +++ b/infra/azure-functions/src/e2e.test.ts @@ -1,4 +1,5 @@ import { test, expect } from 'bun:test'; +import supertest from 'supertest'; const url = process.env.AZURE_FUNCTIONS_URL; const apiKey = process.env.AZURE_FUNCTIONS_API_KEY; @@ -6,6 +7,6 @@ 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 fetch(new URL(`/api/SimpleHttpTrigger?code=${apiKey}`, url).toString()); + const response = await supertest(url).get(`/api/SimpleHttpTrigger?code=${apiKey}`); expect(response.status).toBe(200); }); diff --git a/infra/azure-functions/src/github-actions.ts b/infra/azure-functions/src/github-actions.ts index 4604da2..31bfca7 100644 --- a/infra/azure-functions/src/github-actions.ts +++ b/infra/azure-functions/src/github-actions.ts @@ -47,9 +47,6 @@ export function toGithubActionsMatrix(configs: InfraEnvConfig[]): GithubActionsM */ const version = runtime === 'node18' ? '20' : 'latest'; - if (!config.resourceIdentifier) { - throw new Error('resourceIdentifier is required'); - } return { os: platform === 'linux' ? 'ubuntu-latest' : platform === 'win' ? 'windows-latest' : 'macos-latest', runtime: runtime === 'bun' ? 'bun' : 'node', diff --git a/infra/azure-functions/src/utils.ts b/infra/azure-functions/src/utils.ts index 33a6a5d..5682845 100644 --- a/infra/azure-functions/src/utils.ts +++ b/infra/azure-functions/src/utils.ts @@ -17,8 +17,17 @@ export function createInfraConfig( infraConfigs: InfraEnvConfig[] ): InfraEnvConfig[] { return infraConfigs.map(infraConfig => { - const resourceIdentifier: string = - resourceIdentifiers[toTarget(infraConfig)] ?? fallbackResourceIdentifier(infraConfig); + const resourceIdentifier = resourceIdentifiers[toTarget(infraConfig)]; + + if (!resourceIdentifier && infraConfig.isDeployable) { + throw new Error( + `resourceIdentifier is required for ${toTarget( + infraConfig + )} due to is cannot be deployed. Please provide RESOURCE_IDENTIFIER_${toTarget(infraConfig) + .replaceAll('-', '_') + .toUpperCase()} in env.` + ); + } return { ...infraConfig,