ci: Get api.json from Misskeyでupload-artifact@v4で同名artifactでエラーになるのを修正 (#12770)

* ci: upload-artifact@v4で同名artifactでエラーになるのを修正

Co-authored-by: おさむのひと <46447427+samunohito@users.noreply.github.com>

* report-api-diff.ymlの最中にエラーが発生したときに分かりづらいので、PRにコメントを残すようにする

* 古いget-api-diffを使ってるactionとの互換性をもたせる

---------

Co-authored-by: おさむのひと <46447427+samunohito@users.noreply.github.com>
This commit is contained in:
anatawa12 2023-12-24 14:20:43 +09:00 committed by GitHub
parent 471c8ec050
commit 316ffcea54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 14 deletions

View File

@ -56,7 +56,7 @@ jobs:
- name: Upload Artifact - name: Upload Artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: api-artifact name: api-artifact-${{ matrix.api-json-name }}
path: ${{ matrix.api-json-name }} path: ${{ matrix.api-json-name }}
save-pr-number: save-pr-number:
@ -69,5 +69,5 @@ jobs:
echo "$PR_NUMBER" > ./pr_number echo "$PR_NUMBER" > ./pr_number
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4
with: with:
name: api-artifact name: api-artifact-pr-number
path: pr_number path: pr_number

View File

@ -19,24 +19,28 @@ jobs:
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
script: | script: |
const fs = require('fs');
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
run_id: context.payload.workflow_run.id, run_id: context.payload.workflow_run.id,
}); });
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { let matchArtifacts = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "api-artifact" return artifact.name.startsWith("api-artifact-") || artifact.name == "api-artifact"
})[0]; });
await Promise.all(matchArtifacts.map(async (artifact) => {
let download = await github.rest.actions.downloadArtifact({ let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
artifact_id: matchArtifact.id, artifact_id: artifact.id,
archive_format: 'zip', archive_format: 'zip',
}); });
let fs = require('fs'); await fs.promises.writeFile(`${process.env.GITHUB_WORKSPACE}/${artifact.name}.zip`, Buffer.from(download.data));
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/api-artifact.zip`, Buffer.from(download.data)); }));
- name: Extract artifact - name: Extract all artifacts
run: unzip api-artifact.zip -d artifacts run: |
find . -mindepth 1 -maxdepth 1 -type f -name '*.zip' -exec unzip {} -d artifacts ';'
ls -la
- name: Load PR Number - name: Load PR Number
id: load-pr-num id: load-pr-num
run: echo "pr-number=$(cat artifacts/pr_number)" >> "$GITHUB_OUTPUT" run: echo "pr-number=$(cat artifacts/pr_number)" >> "$GITHUB_OUTPUT"
@ -83,3 +87,11 @@ jobs:
pr_number: ${{ steps.load-pr-num.outputs.pr-number }} pr_number: ${{ steps.load-pr-num.outputs.pr-number }}
comment_tag: show_diff comment_tag: show_diff
filePath: ./output.md filePath: ./output.md
- name: Tell error to PR
uses: thollander/actions-comment-pull-request@v2
if: failure() && steps.load-pr-num.outputs.pr-number
with:
pr_number: ${{ steps.load-pr-num.outputs.pr-number }}
comment_tag: show_diff_error
message: |
api.jsonの差分作成中にエラーが発生しました。詳細は[Workflowのログ](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})を確認してください。