-
Notifications
You must be signed in to change notification settings - Fork 10
132 lines (125 loc) · 5.31 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Publish PR
# read-write repo token
# access to secrets
on:
workflow_run:
workflows: ["Build PR"]
types:
- completed
jobs:
upload:
runs-on: ubuntu-latest
if: |
(
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
)
steps:
- name: download artifacts
uses: actions/[email protected]
with:
script: |
const artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
const snapArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "snap"
})[0];
const prDataArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr-data"
})[0];
if (snapArtifact == null) {
return core.setFailed("Missing artifact");
}
if (prDataArtifact == null) {
return core.setFailed("Missing PR data artifact");
}
const snapDownload = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: snapArtifact.id,
archive_format: 'zip',
});
const prDataDownload = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: prDataArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('${{github.workspace}}/snap.zip', Buffer.from(snapDownload.data));
fs.writeFileSync('${{github.workspace}}/pr-data.zip', Buffer.from(prDataDownload.data));
- name: unzip pr-data
run: unzip pr-data.zip
- name: get PR data
id: get_pr_data
run: |
pr_number="$(cat pr-number)"
pr_commit="$(cat pr-commit)"
echo "::set-output name=pr_number::$pr_number"
echo "::set-output name=pr_commit::$pr_commit"
- name: check if allowed
uses: actions/[email protected]
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ steps.get_pr_data.outputs.pr_number }}
});
if (pr && pr.data.labels) {
const index = pr.data.labels.findIndex(label => (label.name === "safe to publish"));
if (index !== -1) {
return;
}
}
core.setFailed("Pull request needs the 'safe to publish' label");
- name: unzip snap
run: unzip snap.zip
- name: install snapcraft
run: sudo snap install snapcraft --classic
- name: publish snap as branch to edge/pr-$id
id: upload_snap
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.STORE_LOGIN }}
run: |
pr_number="${{ steps.get_pr_data.outputs.pr_number }}"
snap_channel="edge/pr-${pr_number}"
snapcraft upload --release="$snap_channel" freecad*.snap
# get revision
snap_revision=$(snapcraft status freecad --track latest | grep "$snap_channel" | awk '{print $3}')
echo "Snap release channel: ${snap_channel}"
echo "Snap revision: ${snap_revision}"
echo "::set-output name=snap_channel::$snap_channel"
echo "::set-output name=snap_revision::$snap_revision"
- name: comment on PR
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const prNumber = Number(${{ steps.get_pr_data.outputs.pr_number }});
const prCommit = "${{ steps.get_pr_data.outputs.pr_commit }}";
const snapRevision = '${{ steps.upload_snap.outputs.snap_revision }}';
const snapChannel = '${{ steps.upload_snap.outputs.snap_channel }}';
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `A build from commit ${prCommit} has been published to channel ${snapChannel} as revision ${snapRevision}.
## Installation instructions
\`\`\`bash
# Note: not all distros require 'sudo'
$ sudo snap install --channel=${snapChannel} freecad
# If you already have the freecad snap installed
$ sudo snap refresh --channel=${snapChannel} freecad
# Experimental: Parallel install (see https://github.com/FreeCAD/FreeCAD-snap/blob/master/docs/index.md#parallel-installs)
$ sudo snap set system experimental.parallel-instances=true
$ sudo snap install --channel=${snapChannel} freecad_pr${prNumber}
$ freecad_pr${prNumber} # Run it
# To switch back to preferred snap (swap out 'edge' for 'stable' if necessary)
$ snap refresh freecad --channel=edge freecad
\`\`\``
});