Skip to content

Commit

Permalink
feat(github-actions): extract e2e job for deployable flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mildronize committed May 6, 2024
1 parent 8bea0e7 commit f187fd7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
46 changes: 41 additions & 5 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ env:
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
Expand All @@ -43,6 +45,7 @@ jobs:
build:
runs-on: ${{ matrix.os }}
needs: get-matrix
timeout-minutes: 10
strategy:
matrix:
include: ${{fromJson(needs.get-matrix.outputs.matrix)}}
Expand Down Expand Up @@ -73,25 +76,58 @@ 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
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: examples/with-${{ matrix.runtime }}/.nmt/dist
package: .

- 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
Expand Down
3 changes: 1 addition & 2 deletions infra/azure-functions/src/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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;
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 fetch(new URL(`/api/SimpleHttpTrigger?code=${apiKey}`, url).toString());
expect(response.status).toBe(200);
});
4 changes: 4 additions & 0 deletions infra/azure-functions/src/github-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ export function toGithubActionsMatrix(configs: InfraEnvConfig[]): GithubActionsM
const matrix = toGithubActionsMatrix(infraConfigs);
console.log('Github Actions Matrix', JSON.stringify(matrix, null, 2));
core.setOutput('matrix', JSON.stringify(matrix));

const deployableMatrix = matrix.filter(config => config.is_deployable);
console.log('Github Actions Deployable Matrix', JSON.stringify(deployableMatrix, null, 2));
core.setOutput('deployable_matrix', JSON.stringify(deployableMatrix));

0 comments on commit f187fd7

Please sign in to comment.