Skip to content

Commit

Permalink
feat: create a Github release and attach files
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxity committed Mar 21, 2024
1 parent 8892fb5 commit 134ed07
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/server-ci-enterprise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,72 @@ jobs:
path: server/dist/
retention-days: 14

- name: Create GitHub Release
uses: actions/github-script@v7
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
with:
script: |
const fs = require('fs');
const path = require('path');
const tag_name = process.env.GITHUB_REF_NAME;
const release_name = `${tag_name}`;
const body = 'Full Changelog: https://github.com/${context.repo.owner}/${context.repo.repo}/commits/${tag_name}';
const assets = [
'server/dist/mattermost-enterprise-linux-amd64.tar.gz',
'server/dist/mattermost-enterprise-linux-arm64.tar.gz',
'server/dist/mattermost-enterprise-osx-amd64.tar.gz',
'server/dist/mattermost-enterprise-osx-arm64.tar.gz',
'server/dist/mattermost-enterprise-windows-amd64.zip',
];
let releaseId = null;
try {
const createReleaseResponse = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tag_name,
name: release_name,
body: body,
draft: false,
prerelease: false,
});
console.log(`Release created: ${createReleaseResponse.data.html_url}`);
releaseId = createReleaseResponse.data.id;
} catch (error) {
if (error.status === 422) { // Unprocessable Entity - often means the release already exists
console.log(`Release already exists for tag ${tag_name}.`);
} else {
console.error(`Error creating release: ${error}`);
throw error;
}
}
if (releaseId || error.status === 422) {
for (const asset of assets) {
const assetPath = path.join(process.env.GITHUB_WORKSPACE, asset); // Ensure this path is correct
const contentType = asset.endsWith('.zip') ? 'application/zip' : 'application/gzip';
console.log(`Uploading asset: ${asset}`);
try {
const uploadAssetResponse = await github.rest.repos.uploadReleaseAsset({
url: createReleaseResponse.data.upload_url,
headers: {
'content-type': contentType,
'content-length': fs.statSync(assetPath).size
},
name: asset,
data: fs.readFileSync(assetPath),
});
console.log(`Asset uploaded: ${uploadAssetResponse.data.browser_download_url}`);
} catch (uploadError) {
console.error(`Error uploading asset: ${asset}, ${uploadError}`);
}
}
}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

Expand Down

0 comments on commit 134ed07

Please sign in to comment.