This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
chore(deps): update dependency @swc/cli to v0.3.14 #1690
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test and Release | |
on: | |
workflow_dispatch: | |
push: | |
env: | |
LOCATION: norwayeast | |
permissions: | |
id-token: write | |
contents: write | |
issues: write | |
jobs: | |
run-id: | |
name: Create run ID | |
runs-on: ubuntu-22.04 | |
outputs: | |
id: ${{ steps.run-id.outputs.id }} | |
steps: | |
- name: Generate ID | |
id: run-id | |
run: | | |
RUN_ID=`node -e "const crypto = require('crypto'); process.stdout.write(crypto.randomBytes(Math.ceil(8 * 0.5)).toString('hex').slice(0, 8));"` | |
echo "id=${RUN_ID}" >> $GITHUB_OUTPUT | |
mock-api: | |
name: Create mock HTTP API | |
runs-on: ubuntu-22.04 | |
needs: [run-id] | |
outputs: | |
endpoint: ${{ steps.endpoint.outputs.endpoint }} | |
resource-group: ${{ steps.resource-group.outputs.name }} | |
storage-account: ${{ steps.resources.outputs.storage-account }} | |
app-name: ${{ steps.resources.outputs.app-name }} | |
environment: | |
name: ci | |
steps: | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: "20.x" | |
cache: "npm" | |
- name: Install dependencies | |
run: npm ci --no-audit | |
- name: Compile source | |
run: npx tsc | |
- name: Create resource group | |
id: resource-group | |
run: | | |
az group create -n mock-api-${{ needs.run-id.outputs.id }} -l ${{ | |
env.LOCATION }} | |
echo "name=mock-api-${{ needs.run-id.outputs.id }}" >> $GITHUB_OUTPUT | |
- name: Create Mock API | |
id: resources | |
run: | | |
STORAGE_ACCOUNT_NAME=mockapi${{ needs.run-id.outputs.id }} | |
az deployment group create \ | |
--mode Complete \ | |
--name manual-deployment \ | |
--resource-group ${{ steps.resource-group.outputs.name }} \ | |
--template-file mock-http-api.bicep \ | |
--parameters \ | |
storageAccountName=$STORAGE_ACCOUNT_NAME | |
appName=$STORAGE_ACCOUNT_NAME | |
echo "storage-account=${STORAGE_ACCOUNT_NAME}" >> $GITHUB_OUTPUT | |
echo "app-name=${STORAGE_ACCOUNT_NAME}" >> $GITHUB_OUTPUT | |
- name: Get API endpoint | |
id: endpoint | |
run: | | |
MOCK_HTTP_API_ENDPOINT=`az functionapp show -g ${{ steps.resource-group.outputs.name }} -n mockapi${{ needs.run-id.outputs.id }} | jq -r '.defaultHostName'` | |
echo "endpoint=${MOCK_HTTP_API_ENDPOINT}" >> $GITHUB_OUTPUT | |
- name: Deploy the function app | |
run: | | |
npx tsx scripts/pack-mock-http-api-app.ts | |
az functionapp deployment source config-zip -g ${{ steps.resource-group.outputs.name }} -n mockapi${{ needs.run-id.outputs.id }} --src dist/mock-http-api.zip | |
test-resources: | |
name: Create test resources | |
needs: [run-id] | |
runs-on: ubuntu-22.04 | |
environment: | |
name: ci | |
outputs: | |
resource-group: ${{ steps.resource-group.outputs.name }} | |
keyvault-name: ${{ steps.resources.outputs.keyvault-name }} | |
app-name: ${{ steps.resources.outputs.app-name }} | |
steps: | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: "20.x" | |
cache: "npm" | |
- name: Create resource group | |
id: resource-group | |
run: | | |
az group create -n memfault-integration-${{ needs.run-id.outputs.id }} -l ${{ env.LOCATION }} | |
echo "name=memfault-integration-${{ needs.run-id.outputs.id }}" >> $GITHUB_OUTPUT | |
- name: Create test resources | |
id: resources | |
run: | | |
APP_NAME=mfltinttest${{ needs.run-id.outputs.id }} | |
KEYVAULT_NAME=kv-${{ needs.run-id.outputs.id }} | |
az deployment group create \ | |
--mode Complete \ | |
--name manual-deployment \ | |
--resource-group ${{ steps.resource-group.outputs.name }} \ | |
--template-file test-resources.bicep \ | |
--parameters \ | |
appName=${APP_NAME} \ | |
keyVaultName=${KEYVAULT_NAME} | |
echo "keyvault-name=${KEYVAULT_NAME}" >> $GITHUB_OUTPUT | |
echo "app-name=${APP_NAME}" >> $GITHUB_OUTPUT | |
integration-resources: | |
name: Deploy Memfault integration resources | |
needs: [run-id, test-resources] | |
runs-on: ubuntu-22.04 | |
environment: | |
name: ci | |
outputs: | |
storage-account: ${{ steps.resources.outputs.storage-account }} | |
steps: | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: "20.x" | |
cache: "npm" | |
- name: Create integration resources | |
id: resources | |
run: | | |
STORAGE_ACCOUNT_NAME=mfltint${{ needs.run-id.outputs.id }} | |
az deployment group create \ | |
--mode Incremental \ | |
--name memfault-integration-deployment \ | |
--resource-group ${{ needs.test-resources.outputs.resource-group }} \ | |
--template-file memfault-integration.bicep \ | |
--parameters \ | |
appName=${{ needs.test-resources.outputs.app-name }} \ | |
keyVaultName=${{ needs.test-resources.outputs.keyvault-name }} \ | |
storageAccountName=$STORAGE_ACCOUNT_NAME | |
echo "storage-account=${STORAGE_ACCOUNT_NAME}" >> $GITHUB_OUTPUT | |
- name: Deploy the function app | |
run: | | |
npm ci --no-audit | |
npx tsc | |
npx tsx scripts/pack-app.ts | |
az functionapp deployment source config-zip -g ${{ needs.test-resources.outputs.resource-group }} -n ${{ needs.test-resources.outputs.app-name }}-memfault-integration --src dist/functionapp.zip | |
keyvault-settings: | |
name: Store necessary settings in KeyVault | |
runs-on: ubuntu-22.04 | |
needs: [run-id, mock-api, test-resources] | |
environment: | |
name: ci | |
steps: | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Assign 'Key Vault Secrets Officer' permission | |
run: | | |
az role assignment create --role b86a8fe4-44ce-4948-aee5-eccb2c155cd7 \ | |
--assignee ${{ secrets.AZURE_CLIENT_ID }} \ | |
--scope /subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ needs.test-resources.outputs.resource-group }}/providers/Microsoft.KeyVault/vaults/${{ needs.test-resources.outputs.keyvault-name }} | |
- name: Set secrets | |
run: | | |
az keyvault secret set --vault-name ${{ needs.test-resources.outputs.keyvault-name }} --name memfaultProjectKey --value my-projectKey | |
az keyvault secret set --vault-name ${{ needs.test-resources.outputs.keyvault-name }} --name memfaultOrganization --value my-org | |
az keyvault secret set --vault-name ${{ needs.test-resources.outputs.keyvault-name }} --name memfaultProject --value my-project | |
az keyvault secret set --vault-name ${{ needs.test-resources.outputs.keyvault-name }} --name memfaultAuthToken --value my-authToken | |
az keyvault secret set --vault-name ${{ needs.test-resources.outputs.keyvault-name }} --name memfaultApiEndpoint --value "https://${{ needs.mock-api.outputs.endpoint }}/api/api.memfault.com/" | |
az keyvault secret set --vault-name ${{ needs.test-resources.outputs.keyvault-name }} --name memfaultChunksEndpoint --value "https://${{ needs.mock-api.outputs.endpoint }}/api/chunks.memfault.com/" | |
test: | |
name: Run end-to-end tests | |
runs-on: ubuntu-22.04 | |
needs: [test-resources, mock-api, keyvault-settings, integration-resources] | |
environment: | |
name: ci | |
steps: | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: "20.x" | |
cache: "npm" | |
- name: Install dependencies | |
run: npm ci --no-audit | |
- name: Compile source | |
run: npx tsc | |
- name: Compile TypeScript | |
run: npx tsc | |
- name: Check source code with eslint | |
run: npx eslint . | |
- name: Check if source code is properly formatted | |
run: npx prettier -c ./ | |
- name: Run Unit Tests | |
run: npm test | |
- name: Run tests | |
env: | |
IOT_HUB_NAME: ${{ needs.test-resources.outputs.app-name }}IotHub | |
RESOURCE_GROUP: ${{ needs.test-resources.outputs.resource-group }} | |
MOCK_API_RESOURCE_GROUP: ${{ needs.mock-api.outputs.resource-group }} | |
MOCK_API_STORAGE_ACCOUNT_NAME: | |
${{ needs.mock-api.outputs.storage-account }} | |
MOCK_API_APP_NAME: ${{ needs.mock-api.outputs.app-name }} | |
run: | | |
npm run test:e2e | |
cat e2e-test-result.json | npx tsx feature-runner/markdown-reporter.ts >> $GITHUB_STEP_SUMMARY | |
- uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
if-no-files-found: error | |
name: e2e-test-result-${{ github.sha }} | |
path: e2e-test-result.json | |
cleanup-test-resources: | |
name: Clean up test resources | |
runs-on: ubuntu-22.04 | |
needs: [test, test-resources] | |
if: always() && !cancelled() | |
environment: | |
name: ci | |
steps: | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Delete resource group | |
if: always() | |
run: | |
az group delete -n ${{ needs.test-resources.outputs.resource-group }} | |
-y | |
cleanup-mock-api: | |
name: Clean up mock HTTP API resources | |
runs-on: ubuntu-22.04 | |
needs: [test, mock-api] | |
if: always() && !cancelled() | |
environment: | |
name: ci | |
steps: | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Delete Mock API resource group | |
if: always() | |
run: az group delete -n ${{ needs.mock-api.outputs.resource-group }} -y | |
release: | |
needs: | |
- test | |
runs-on: ubuntu-22.04 | |
if: github.ref == 'refs/heads/saga' | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: "20.x" | |
cache: "npm" | |
- name: Install dependencies | |
run: npm ci --no-audit | |
- name: Semantic release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: npx semantic-release |