-
Notifications
You must be signed in to change notification settings - Fork 38
76 lines (71 loc) · 2.67 KB
/
publish-pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: Publish PR
on:
workflow_run:
workflows: ['Main CI']
types:
- completed
permissions:
contents: read
jobs:
version:
if: ${{ github.event.workflow_run.event == 'pull_request' }}
permissions:
actions: read
runs-on: ubuntu-latest
outputs:
nextVersionTag: ${{ steps.newVersion.outputs.nextVersionTag }}
steps:
- name: get logs from workflow run
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
let download = await github.rest.actions.downloadWorkflowRunAttemptLogs({
...context.repo,
run_id: context.payload.workflow_run.id,
attempt_number: 1
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/logs.zip`, Buffer.from(download.data));
- run: unzip logs.zip
- name: extract version from logs
id: newVersion
run: echo nextVersionTag=$(find -name '*_version.txt' | xargs grep -hiPo '(?<=nextVersionTag variable has been set with ).*$') >> "$GITHUB_OUTPUT"
publish-packages-pr:
uses: ./.github/workflows/publish.yml
needs: [version]
permissions:
contents: read
# Needed to publish with provenance (not needed for pull-request but requested by publish.yml workflow)
id-token: write
secrets: inherit
with:
version: ${{ needs.version.outputs.nextVersionTag }}-${{ github.event.workflow_run.run_attempt }}
prerelease: true
isPullRequest: true
gitRef: ${{ github.event.workflow_run.pull_requests[0].base.ref }}
notify-parent:
runs-on: ubuntu-latest
needs: [publish-packages-pr]
if: success() || failure()
permissions:
# Needed to notify the parent workflow
checks: write
steps:
- name: Update triggering workflow
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
env:
PUBLISH_RESULT: ${{ needs.publish-packages-pr.result }}
with:
script: |
const backUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/attempts/${context.runAttempt || 1}`;
await github.rest.checks.create({
...context.repo,
head_sha: context.payload.workflow_run.head_commit.id,
name: 'publish-packages-pr',
conclusion: process.env.PUBLISH_RESULT,
status: 'completed',
output: {
title: 'publish-packages-pr',
summary: `${process.env.PUBLISH_RESULT} publish [${backUrl}](${backUrl})`
}
});