unit-test-post.yml 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. name: unit-test-post
  2. on:
  3. workflow_run:
  4. workflows: [ "unit-test" ]
  5. types: [ completed ]
  6. jobs:
  7. publish-test-results:
  8. if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
  9. runs-on: ubuntu-latest
  10. steps:
  11. - name: Download analysis results
  12. uses: actions/github-script@v3.1.0
  13. with:
  14. script: |
  15. let artifacts = await github.actions.listWorkflowRunArtifacts({
  16. owner: context.repo.owner,
  17. repo: context.repo.repo,
  18. run_id: ${{github.event.workflow_run.id }},
  19. });
  20. let matchArtifact = artifacts.data.artifacts.filter((artifact) => {
  21. return artifact.name == "test-result"
  22. })[0];
  23. let download = await github.actions.downloadArtifact({
  24. owner: context.repo.owner,
  25. repo: context.repo.repo,
  26. artifact_id: matchArtifact.id,
  27. archive_format: "zip",
  28. });
  29. let fs = require("fs");
  30. fs.writeFileSync("${{github.workspace}}/test-result.zip", Buffer.from(download.data));
  31. - name: Set environment variables
  32. run: |
  33. mkdir pr_env
  34. unzip test-result.zip -d pr_env
  35. echo "pr_id=$(cat pr_env/pr-id.txt)" >> $GITHUB_ENV
  36. echo "pr_head_repo=$(cat pr_env/pr-head-repo.txt)" >> $GITHUB_ENV
  37. echo "pr_head_ref=$(cat pr_env/pr-head-ref.txt)" >> $GITHUB_ENV
  38. - uses: actions/checkout@v3
  39. with:
  40. repository: ${{ env.pr_head_repo }}
  41. ref: ${{ env.pr_head_ref }}
  42. persist-credentials: false
  43. - name: Redownload analysis results
  44. uses: actions/github-script@v3.1.0
  45. with:
  46. script: |
  47. let artifacts = await github.actions.listWorkflowRunArtifacts({
  48. owner: context.repo.owner,
  49. repo: context.repo.repo,
  50. run_id: ${{github.event.workflow_run.id }},
  51. });
  52. let matchArtifact = artifacts.data.artifacts.filter((artifact) => {
  53. return artifact.name == "test-result"
  54. })[0];
  55. let download = await github.actions.downloadArtifact({
  56. owner: context.repo.owner,
  57. repo: context.repo.repo,
  58. artifact_id: matchArtifact.id,
  59. archive_format: "zip",
  60. });
  61. let fs = require("fs");
  62. fs.writeFileSync("${{github.workspace}}/test-result.zip", Buffer.from(download.data));
  63. - name: Extract analysis results
  64. run: |
  65. mkdir -p tests
  66. unzip test-result.zip -d tests
  67. - name: Publish Unit Test Results
  68. id: test-results
  69. uses: EnricoMi/publish-unit-test-result-action@v1
  70. with:
  71. files: "tests/**/*.xml"
  72. - name: Conclusion
  73. run: echo "Conclusion is ${{ fromJSON( steps.test-results.outputs.json ).conclusion }}"