diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..de8c177 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,42 @@ +name: Test Action + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Copy meshstack_token.json to temp directory + run: | + mkdir -p $RUNNER_TEMP + cp test_data/meshstack_token.json $RUNNER_TEMP/meshstack_token.json + + + - name: Setup Meshstack Authentication + id: setup-meshstack-auth + uses: meshcloud/actions-register-source@main + with: + steps: | + [ + { "id": "terraform-validate", "displayName": "terraform validate" }, + { "id": "terraform-plan", "displayName": "terraform plan" }, + { "id": "terraform-apply", "displayName": "terraform apply" } + ] + client_id: ${{ secrets.CLIENT_ID }} + key_secret: ${{ secrets.KEY_SECRET }} + + - name: Run Action + id: run-action + uses: ./ + with: + step_id: 'terrafrom-validate' + status: 'SUCCESS' + user_message: 'User message' + system_message: 'System message' + is_final: 'true' + summary: 'Summary message' + + - name: Display temp directory + run: echo "Temporary directory is ${{ steps.run-action.outputs.temp_directory }}" + diff --git a/dist/index.js b/dist/index.js index 3aaa9e1..f4b97ce 100644 --- a/dist/index.js +++ b/dist/index.js @@ -40,8 +40,8 @@ const path = __importStar(__nccwpck_require__(1017)); const os = __importStar(__nccwpck_require__(2037)); async function run() { try { - // const baseUrl = core.getInput('base_url'); - // const bbRunUuid = core.getInput('bb_run_uuid'); + let baseUrl; + let bbRunUuid; const stepId = core.getInput('step_id'); const status = core.getInput('status'); const userMessage = core.getInput('user_message'); @@ -54,8 +54,6 @@ async function run() { // Set the temporary directory path as an output core.setOutput('temp_directory', tempDir); let token; - let baseUrl; - let bbRunUuid; try { const tokenFilePath = path.join(tempDir, 'meshstack_token.json'); core.debug(`Token file path: ${tokenFilePath}`); @@ -83,17 +81,16 @@ async function run() { status: isFinal ? status : "IN_PROGRESS", steps: [{ id: stepId, - status: status + status: status, + userMessage: userMessage, + systemMessage: systemMessage }] }; - if (status === 'FAILED') { - data.steps[0].userMessage = userMessage; - data.steps[0].systemMessage = systemMessage; - } if (isFinal) { data.summary = summary; - data.steps = []; } + core.debug(`Constructed data object: ${JSON.stringify(data)}`); + console.log(`Constructed data object: ${JSON.stringify(data)}`); const response = await axios_1.default.patch(`${baseUrl}/api/meshobjects/meshbuildingblockruns/${bbRunUuid}/status/source/github`, data, { headers: { 'Content-Type': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json', diff --git a/src/index.ts b/src/index.ts index 9e2c170..79b5c48 100644 --- a/src/index.ts +++ b/src/index.ts @@ -48,9 +48,6 @@ async function run() { return; } - core.debug(`Constructed data object: ${JSON.stringify(data)}`); - console.log(`Constructed data object: ${JSON.stringify(data)}`); - const data: any = { status: isFinal ? status : "IN_PROGRESS", steps: [{ @@ -63,9 +60,11 @@ async function run() { if (isFinal) { data.summary = summary; - data.steps = []; } + core.debug(`Constructed data object: ${JSON.stringify(data)}`); + console.log(`Constructed data object: ${JSON.stringify(data)}`); + const response = await axios.patch( `${baseUrl}/api/meshobjects/meshbuildingblockruns/${bbRunUuid}/status/source/github`, data, diff --git a/test_data/event.json b/test_data/event.json new file mode 100644 index 0000000..59573c9 --- /dev/null +++ b/test_data/event.json @@ -0,0 +1,5 @@ +{ + "inputs": { + "buildingBlockRun": "eyJtZXRhZGF0YSI6eyJ1dWlkIjoiZWM3YjgyMTMtNDk0YS00MDAyLTlhNGYtOGQzMjEwMThlN2Q4In0sIl9saW5rcyI6eyJtZXNoc3RhY2tCYXNlVXJsIjp7ImhyZWYiOiJodHRwczovL2ZlZGVyYXRpb24uZGV2Lm1lc2hjbG91ZC5pbyJ9fSwic3BlYyI6eyJidWlsZGluZ0Jsb2NrIjp7InNwZWMiOnsiaW5wdXRzIjpbeyJwcm9qZWN0TmFtZSI6ImV4YW1wbGVQcm9qZWN0IiwiZW5pcm9ubWVudCI6InByb2R1Y3Rpb24iLCJyZWdpb24iOiJ1cy13ZXN0LTEifV19fX19Cg==" + } +}