Skip to content

Commit

Permalink
Version update to v1.0.0, revision f5beac5
Browse files Browse the repository at this point in the history
QA Wolf bot committed Oct 21, 2024
1 parent f715434 commit fa53706
Showing 7 changed files with 34,107 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## v1.0.0

- New Github action to upload a file to the run inputs executables bucket.
75 changes: 74 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,74 @@
# upload-run-inputs-executable-action
# Notify QA Wolf on Deploy

## Introduction

This action uploads a executable file to be used in a test workflow. this action uses [the `@qawolf/ci-sdk`
package](https://www.npmjs.com/package/@qawolf/ci-sdk).

### `qawolf-api-key`

**Required**. The QA Wolf API key, which you can find on the application's team settings page.

### `input-file-path`

**Required**. The path to the file to be uploaded. Must exist at this location on the file system.

## Outputs

### `destination-file-path`

The location the file will be available at in the playground's file system.

### Usage Example

```yml
name: Upload Run Input File
on: workflow_dispatch:
jobs:
upload-input-file:
runs-on: ubuntu-latest
steps:
....
- name: Upload Run Input
uses: qawolf/upload-run-inputs-executable-action@v1
with:
qawolf-api-key: "${{ secrets.QAWOLF_API_KEY }}"
input-file-path: "path/to/file.apk"
....
```

### Usage within in a Trigger Workflow

The `qawolf/upload-run-inputs-executable-action` will output `destination-file-path` with the location the file will be available at in the playground's file system. To use this in a test workflow you can add this value as a `RUN_INPUT_PATH` environmental variable in the `qawolf/notify-qawolf-on-deploy-action@v1` action.

For official documentation on Triggering test runs refer to [Trigger test runs on deployment](https://qawolf.notion.site/Triggering-test-runs-on-deployment-0f12fb5260de4362a5ebe33d8a2f9538)

Official documentation for the Notify QA Wolf on Deploy Action is located at [Notify QA Wolf on Deploy Action] (https://github.com/marketplace/actions/notify-qa-wolf-on-deploy)

```yml
name: Deploy and Notify QA Wolf
on: pull_request
jobs:
...
notify:
needs: deploy-preview-environmnent
name: Trigger QA Wolf PR testing
runs-on: ubuntu-latest
steps:
...
# Upload the run input file
- name: Upload Run Input
id: upload-run-inputs-executable
uses: qawolf/upload-run-inputs-executable-action@v1
with:
qawolf-api-key: "${{ secrets.QAWOLF_API_KEY }}"
input-file-path: "path/to/file.apk"
- name: Notify QA Wolf of deployment
uses: qawolf/notify-qawolf-on-deploy-action@v1
env:
...
# Use the output in the RUN_INPUT_PATH environmental variable
RUN_INPUT_PATH: "${{ steps.upload-run-inputs-executable.outputs.destination-file-path }}"
...
with: ...
```
18 changes: 18 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Upload Run Inputs Executable"
description: "Uploads a file to the run inputs executables bucket"
branding:
icon: "git-merge"
color: "purple"
inputs:
qawolf-api-key:
description: "QA Wolf API key. You can find it in the application team settings page."
required: true
input-file-path:
description: "Path to the file to be uploaded."
required: true
outputs:
destination-file-path:
description: "The file location in the QA Wolf runs file system."
runs:
using: "node20"
main: "dist/index.js"
33,872 changes: 33,872 additions & 0 deletions dist/index.js

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@qawolf/upload-run-inputs-executable-action",
"version": "v1.0.0",
"type": "commonjs",
"main": "dist/index.js",
"engines": {
"node": "^18 || >=20"
},
"scripts": {
"build": "ncc build src/index.ts -o dist",
"build:clean": "tsc --build --clean && rm -rf ./dist",
"lint": "eslint . --ext js,jsx,mjs,ts,tsx --quiet && prettier --check .",
"lint:fix": "eslint . --ext js,jsx,mjs,ts,tsx --fix --quiet && prettier --log-level=warn --write .",
"lint:warnings": "eslint . --ext js,jsx,mjs,ts,tsx",
"test": "jest --passWithNoTests",
"test:watch": "npm run test -- --watch",
"tsc:check": "tsc",
"gen": "npm run build"
},
"dependencies": {
"@actions/core": "^1.10.1",
"@qawolf/ci-sdk": "*",
"@qawolf/ci-utils": "*",
"tslib": "^2.5.3"
},
"devDependencies": {
"@vercel/ncc": "^0.38.1"
}
}
84 changes: 84 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import * as core from "@actions/core";
import fs from "fs/promises";
import path from "path";

import { makeQaWolfSdk } from "@qawolf/ci-sdk";
import { coreLogDriver, stringifyUnknown } from "@qawolf/ci-utils";

import { validateInput } from "./validateInput";

async function runGitHubAction() {
core.debug("Validating input.");
const validationResult = validateInput();
if (!validationResult.isValid) {
core.setFailed(`Action input is invalid: ${validationResult.error}`);
return;
}
const { apiKey, generateSignedUrlConfig } = validationResult;
const { generateSignedUrlForRunInputsExecutablesStorage } = makeQaWolfSdk(
{ apiKey },
{
log: coreLogDriver,
},
);

core.info("Beginning signed URL generation for file upload.");

// Always upload to the root of team's run inputs executables directory.
const fileName = path.basename(generateSignedUrlConfig.destinationFilePath);

const generateSignedUrlResult =
await generateSignedUrlForRunInputsExecutablesStorage({
destinationFilePath: fileName,
});
if (!generateSignedUrlResult.success) {
core.setFailed(
`Failed to generate signed URL with reason "${generateSignedUrlResult.abortReason}" ${
generateSignedUrlResult.httpStatus
? `, HTTP status ${generateSignedUrlResult.httpStatus}`
: ""
}.`,
);
return;
}

const fileBuffer = await fs.readFile(
generateSignedUrlConfig.destinationFilePath,
);

const url = generateSignedUrlResult.uploadUrl;

if (!url) {
core.setFailed(`Failed to recieve upload URL`);
return;
}

try {
const response = await fetch(url, {
body: fileBuffer,
headers: {
"Content-Type": "application/octet-stream",
},
method: "PUT",
});

if (!response.ok)
throw Error(`Failed to upload file: ${response.statusText}`);
} catch (error) {
core.setFailed(`Failed to upload file: ${error}`);
return;
}

core.setOutput(
"destination-file-path",
generateSignedUrlResult.playgroundFileLocation,
);

core.info(`Successfully uploaded the file ${fileName}.`);
}

runGitHubAction().catch((error) => {
core.setFailed(
`Action failed with reason: ${stringifyUnknown(error) ?? "Unknown error"}`,
);
});
27 changes: 27 additions & 0 deletions src/validateInput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as core from "@actions/core";

import { type GenerateSignedUrlConfig } from "@qawolf/ci-sdk";
export function validateInput():
| {
apiKey: string;
generateSignedUrlConfig: GenerateSignedUrlConfig;
isValid: true;
}
| {
error: string;
isValid: false;
} {
const qawolfApiKey = core.getInput("qawolf-api-key", {
required: true,
});

const destinationFilePath = core.getInput("input-file-path", {
required: true,
});

return {
apiKey: qawolfApiKey,
generateSignedUrlConfig: { destinationFilePath },
isValid: true,
};
}

0 comments on commit fa53706

Please sign in to comment.