From 381990e07f77975196081b020e07b8849e000e60 Mon Sep 17 00:00:00 2001 From: Nathan Miller Date: Wed, 21 Feb 2024 12:28:08 -0800 Subject: [PATCH 1/2] fix syntax for JS dispatch payload --- .github/workflows/docker-publish.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 3bf94bfb..98405baa 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -147,9 +147,9 @@ jobs: with: repository: ${{ github.repository }} event-type: trigger_deploy_release_event - client-payload: > - '{ - "ref_name": "${{ github.ref_name }}", - "run_number": "${{ github.run_number }}", - "dispatch_id": "${{ secrets.DISPATCH_ID }}" + client-payload: | + '{ \ + "ref_name": "${{ github.ref_name }}", \ + "run_number": "${{ github.run_number }}", \ + "dispatch_id": "${{ secrets.DISPATCH_ID }}" \ }' From b776a26635106e364e061a0a1200b69e48fa5045 Mon Sep 17 00:00:00 2001 From: Nathan Miller Date: Wed, 21 Feb 2024 13:00:29 -0800 Subject: [PATCH 2/2] convert create release step to use a function from a file --- .github/workflows/create-release.yml | 46 +-------------- scripts/create-release.js | 85 +++++++++++++++------------- 2 files changed, 48 insertions(+), 83 deletions(-) diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 3baf7f1f..3d9bf482 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -96,47 +96,5 @@ jobs: with: github-token: "${{ secrets.GITHUB_TOKEN }}" script: | - try { - const createResponse = await github.rest.repos.createRelease({ - generate_release_notes: true, - name: process.env.RELEASE_NAME, - owner: context.repo.owner, - repo: context.repo.repo, - prerelease: false, - tag_name: process.env.RELEASE_TAG, - body: require('fs').readFileSync('${{ github.workspace }}/release/release-body.md', 'utf8'), - target_commitish: '${{ github.event.client_payload.ref_name }}' - }); - - const files = - [ - { name: 'OdbDesign-Linux-x64.zip', contentType: 'application/zip' }, - { name: 'OdbDesign-Linux-x64.zip.sha256sum', contentType: 'text/plain' }, - { name: 'OdbDesign-Linux-x64.zip.asc', contentType: 'text/plain' }, - { name: 'OdbDesign-Windows-x64.zip', contentType: 'application/zip' }, - { name: 'OdbDesign-Windows-x64.zip.sha256sum', contentType: 'text/plain' }, - { name: 'OdbDesign-Windows-x64.zip.asc', contentType: 'text/plain' }, - { name: 'OdbDesign-MacOS-x64.zip', contentType: 'application/zip' }, - { name: 'OdbDesign-MacOS-x64.zip.sha256sum', contentType: 'text/plain' }, - { name: 'OdbDesign-MacOS-x64.zip.asc', contentType: 'text/plain' } - ]; - - const artifactsPath = '${{ github.workspace }}/artifacts'; - - for (const file of files) { - const filePath = artifactsPath +'/' + file.name; - const uploadResponse = await github.rest.repos.uploadReleaseAsset({ - owner: context.repo.owner, - repo: context.repo.repo, - release_id: createResponse.data.id, - name: file.name, - data: require('fs').readFileSync(filePath), - headers: { - 'content-type': file.contentType, - 'content-length': require('fs').statSync(filePath).size - } - }); - } - } catch (error) { - core.setFailed(error.message); - } + const script = require('./scripts/create-release.js') + script({github, context, core}, '${{ github.workspace }}', '${{ github.ref_name }}') diff --git a/scripts/create-release.js b/scripts/create-release.js index 2d8db6dd..c275fec7 100644 --- a/scripts/create-release.js +++ b/scripts/create-release.js @@ -1,44 +1,51 @@ -try { - const createResponse = await github.rest.repos.createRelease({ - generate_release_notes: true, - name: process.env.RELEASE_NAME, - owner: context.repo.owner, - repo: context.repo.repo, - prerelease: false, - tag_name: process.env.RELEASE_TAG, - body: require('fs').readFileSync('${{ github.workspace }}/release/release-body.md', 'utf8'), - target_commitish: '${{ github.ref_name }}' - }); +async function createRelease({github, context, core}, workspacePath, refName) { - const files = - [ - { name: 'OdbDesign-Linux-x64.zip', contentType: 'application/zip' }, - { name: 'OdbDesign-Linux-x64.zip.sha256sum', contentType: 'text/plain' }, - { name: 'OdbDesign-Linux-x64.zip.asc', contentType: 'text/plain' }, - { name: 'OdbDesign-Windows-x64.zip', contentType: 'application/zip' }, - { name: 'OdbDesign-Windows-x64.zip.sha256sum', contentType: 'text/plain' }, - { name: 'OdbDesign-Windows-x64.zip.asc', contentType: 'text/plain' }, - { name: 'OdbDesign-MacOS-x64.zip', contentType: 'application/zip' }, - { name: 'OdbDesign-MacOS-x64.zip.sha256sum', contentType: 'text/plain' }, - { name: 'OdbDesign-MacOS-x64.zip.asc', contentType: 'text/plain' } - ]; - - const artifactsPath = '${{ github.workspace }}/artifacts'; - - for (const file of files) { - const filePath = artifactsPath +'/' + file.name; - const uploadResponse = await github.rest.repos.uploadReleaseAsset({ + try { + const createResponse = await github.rest.repos.createRelease({ + generate_release_notes: true, + name: process.env.RELEASE_NAME, owner: context.repo.owner, repo: context.repo.repo, - release_id: createResponse.data.id, - name: file.name, - data: require('fs').readFileSync(filePath), - headers: { - 'content-type': file.contentType, - 'content-length': require('fs').statSync(filePath).size - } + prerelease: false, + tag_name: process.env.RELEASE_TAG, + body: require('fs').readFileSync(workspacePath + '/' + 'release/release-body.md', 'utf8'), + target_commitish: refName }); + + const files = + [ + { name: 'OdbDesign-Linux-x64.zip', contentType: 'application/zip' }, + { name: 'OdbDesign-Linux-x64.zip.sha256sum', contentType: 'text/plain' }, + { name: 'OdbDesign-Linux-x64.zip.asc', contentType: 'text/plain' }, + { name: 'OdbDesign-Windows-x64.zip', contentType: 'application/zip' }, + { name: 'OdbDesign-Windows-x64.zip.sha256sum', contentType: 'text/plain' }, + { name: 'OdbDesign-Windows-x64.zip.asc', contentType: 'text/plain' }, + { name: 'OdbDesign-MacOS-x64.zip', contentType: 'application/zip' }, + { name: 'OdbDesign-MacOS-x64.zip.sha256sum', contentType: 'text/plain' }, + { name: 'OdbDesign-MacOS-x64.zip.asc', contentType: 'text/plain' } + ]; + + const artifactsPath = workspacePath + '/' + 'artifacts'; + + for (const file of files) { + const filePath = artifactsPath + '/' + file.name; + const uploadResponse = await github.rest.repos.uploadReleaseAsset({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: createResponse.data.id, + name: file.name, + data: require('fs').readFileSync(filePath), + headers: { + 'content-type': file.contentType, + 'content-length': require('fs').statSync(filePath).size + } + }); + } + } catch (error) { + core.setFailed(error.message); } -} catch (error) { - core.setFailed(error.message); -} \ No newline at end of file + + return context.payload.client_payload.value +} + +module.exports = createRelease; \ No newline at end of file