Skip to content

Commit

Permalink
Merge pull request #133 from modos189/fix/github-actions
Browse files Browse the repository at this point in the history
Fix comment publishing action
  • Loading branch information
modos189 authored May 5, 2024
2 parents 5555c25 + 51a674b commit 45efb81
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
FILE_NAME="${FILE_NAME}-$(echo ${{ github.event.pull_request.head.sha }} | cut -c 1-6)"
echo "PR" > ./build/.metadata/build_type
echo ${{ github.event.pull_request.head.sha }} > ./build/.metadata/commit
echo ${{ github.event.number }} > ./build/.metadata/pr_number
fi
mv $ORIGINAL_FILE_NAME "./build/$FILE_NAME".zip
Expand All @@ -76,7 +77,7 @@ jobs:
- uses: ncipollo/release-action@v1
if: startsWith(github.ref, 'refs/tags/v')
env:
FILE_PATH: ./build/${{ env.FILE_NAME }}
FILE_PATH: ./build/${{ env.FILE_NAME }}.zip
with:
allowUpdates: true
artifactErrorsFailBuild: true
Expand Down
40 changes: 33 additions & 7 deletions .github/workflows/comment-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,52 @@ jobs:
});
artifacts.data.artifacts.forEach((artifact, index) => {
const nameVar = `artifact${index + 1}`;
const displayNameVar = `displayArtifact${index + 1}`;
const urlVar = `url${index + 1}`;
let displayName = artifact.name.endsWith('-artifacts') ? `**${artifact.name}**` : artifact.name;
core.exportVariable(nameVar, displayName);
core.exportVariable(nameVar, artifact.name);
core.exportVariable(displayNameVar, displayName);
core.exportVariable(urlVar, `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/artifacts/${artifact.id}`);
});
core.exportVariable("firstArtifactId", artifacts.data.artifacts[0].id);
- name: Download first artifact
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: ${{ env.firstArtifactId }},
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/build.zip`, Buffer.from(download.data));
- name: Extract PR number from artifact
run: |
unzip build.zip
if [ -f ".metadata/pr_number" ]; then
PR_NUMBER=$(cat .metadata/pr_number)
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
fi
- name: Comment with artifact links for PR
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ env.PR_NUMBER != '' }}
with:
header: pr_artifacts
number: ${{ github.event.workflow_run.pull_requests[0].number }}
number: ${{ env.PR_NUMBER }}
message: |
Build completed successfully. Below are the download links for the build artifacts:
| Artifact Name | Download Link |
| ------------- | ------------- |
| ${{ env.artifact1 }} | [Download](${{ env.url1 }}) |
| ${{ env.artifact2 }} | [Download](${{ env.url2 }}) |
| ${{ env.artifact3 }} | [Download](${{ env.url3 }}) |
| ${{ env.artifact4 }} | [Download](${{ env.url4 }}) |
| ${{ env.artifact5 }} | [Download](${{ env.url5 }}) |
| ${{ env.displayArtifact1 }} | [Download](${{ env.url1 }}) |
| ${{ env.displayArtifact2 }} | [Download](${{ env.url2 }}) |
| ${{ env.displayArtifact3 }} | [Download](${{ env.url3 }}) |
| ${{ env.displayArtifact4 }} | [Download](${{ env.url4 }}) |
| ${{ env.displayArtifact5 }} | [Download](${{ env.url5 }}) |
Artifacts will only be retained for 90 days.

0 comments on commit 45efb81

Please sign in to comment.