Github workFlow发布release失败
常见问题
Error: Unhandled error: TypeError: Cannot read properties of undefined (reading 'uploadReleaseAsset')
release.yml
中的配置actions/github-script@v7对应api应该为github.rest.repos.uploadReleaseAsset
- name: Upload a Release Asset
uses: actions/github-script@v7
if: github.event_name == 'release'
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log('environment', process.versions);
const fs = require('fs').promises;
const { repo: { owner, repo }, sha } = context;
console.log({ owner, repo, sha });
const releaseId = process.env.RELEASE_ID
const artifactPathName = process.env.ARTIFACT_PATHNAME
const artifactName = process.env.ARTIFACT_NAME
console.log('Releasing', releaseId, artifactPathName, artifactName)
await github.repos.uploadReleaseAsset({
owner, repo,
release_id: releaseId,
name: artifactName,
data: await fs.readFile(artifactPathName)
});
Error: Resource not accessible by integration
release.yml
中的 GitHub 环境令牌 GITHUB_TOKEN
由 GitHub 为每个运行的工作流自动颁发,无需进一步配置,这意味着没有秘密泄露的风险。但是,此令牌在默认情况下仅具有读取权限,在运行工作流时可能会收到 Resource not accessible by integration
(资源无法通过集成访问)错误。如果发生这种情况,需要为此令牌添加写入权限。为此,请前往 GitHub 仓库 Settings
,然后选择 Actions
,向下滚动到 Workflow permissions
(工作流权限)并选中 Read and write permissions
(读取和写入权限)。
Settings -> Actions -> General -> Workflow permissions -> Read and write permissions
Action 意外终止
如果 Action 因某些原因(如缓存错误,依赖下载失败等)终止工作流,不需要重新创建 tag
来触发工作流,可以通过 Re-run all jobs
按钮来重新触发。