Skip to content

Publish Build Artifacts #44

Publish Build Artifacts

Publish Build Artifacts #44

name: Publish Build Artifacts
on:
workflow_run:
workflows: [CI]
types: [completed]
branches: [master]
jobs:
check-publishing-enabled:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
outputs:
SHOULD_PUBLISH: ${{ steps.check.outputs.SHOULD_PUBLISH }}
steps:
- name: Check if publishing is enabled
id: check
run: echo "SHOULD_PUBLISH=${{ env.PUBLISH_ENABLED != ''}}" >> $GITHUB_OUTPUT
env:
PUBLISH_ENABLED: ${{ vars.ENABLE_PRERELEASE_ARTIFACT_PUBLISHING }}
publish-artifacts:
runs-on: ubuntu-latest
needs: [check-publishing-enabled]
if: needs.check-publishing-enabled.outputs.SHOULD_PUBLISH == 'true'
steps:
- uses: actions/checkout@v3
- run: |
mkdir artifacts
echo "updated_on=$(/bin/date -u '+%Y-%m-%d %H:%M')" >> $GITHUB_ENV
- name: Download Build Artifacts
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
await Promise.all(allArtifacts.data.artifacts.map(async function(art) {
if (art.name.match(/-debug/)) return; // Skip debug artifacts
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: art.id,
archive_format: 'zip',
});
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/artifacts/${art.name}.zip`, Buffer.from(download.data));
}));
- name: Delete Previous Release
uses: dev-drprasad/delete-tag-and-release@v1.0.1
with:
tag_name: last-successful
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Update Release
id: release
uses: softprops/action-gh-release@v0.1.15
with:
prerelease: true
tag_name: last-successful
name: "Last successful build (unstable)"
files: 'artifacts/*.zip'
body_path: '.github/PRERELEASE_NOTES.md'