Skip to content

Commit

Permalink
Create release js file (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
nam20485 committed Feb 21, 2024
2 parents d26d62a + b776a26 commit 76f7c6b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 88 deletions.
46 changes: 2 additions & 44 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}')
10 changes: 5 additions & 5 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}" \
}'
85 changes: 46 additions & 39 deletions scripts/create-release.js
Original file line number Diff line number Diff line change
@@ -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);
}

return context.payload.client_payload.value
}

module.exports = createRelease;

0 comments on commit 76f7c6b

Please sign in to comment.