-
Notifications
You must be signed in to change notification settings - Fork 1
162 lines (137 loc) · 4.98 KB
/
pr-binaries.yml
File metadata and controls
162 lines (137 loc) · 4.98 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: PR Binaries
on:
workflow_dispatch:
# Prevent multiple runs on the same branch
concurrency:
group: pr-binaries-${{ github.ref }}
cancel-in-progress: true
jobs:
detect-pr:
runs-on: ubuntu-latest
outputs:
pr_number: ${{ steps.find_pr.outputs.pr_number }}
steps:
- name: Find PR for this branch
id: find_pr
uses: actions/github-script@v7
with:
script: |
const branch = context.ref.replace('refs/heads/', '');
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:${branch}`,
state: 'open'
});
if (pulls.length === 0) {
core.setFailed(`No open PR found for branch: ${branch}`);
return;
}
const prNumber = pulls[0].number;
core.setOutput('pr_number', prNumber);
core.info(`Found PR #${prNumber} for branch ${branch}`);
setup:
needs: [detect-pr]
runs-on: ubuntu-latest
outputs:
version: ${{ steps.latest_version.outputs.version }}
env:
PR_NUMBER: ${{ needs.detect-pr.outputs.pr_number }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set build numbers
run: |
LAST_TAG=$(git tag --sort=-version:refname | head -1)
echo "DRIFT_BUILD=$(git rev-list --count $LAST_TAG..HEAD)" >> $GITHUB_ENV
echo "DRIFT_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Build prerelease version
uses: miniscruff/changie-action@v2
with:
args: batch auto --prerelease dev.${{ env.DRIFT_BUILD }}.${{ env.DRIFT_COMMIT }}.pr${{ env.PR_NUMBER }}
- name: Merge changes
uses: miniscruff/changie-action@v2
with:
args: merge
- name: Get latest version
id: changie_latest
uses: miniscruff/changie-action@v2
with:
args: latest --remove-prefix
- name: Export version
id: latest_version
run: |
echo "version=${{ steps.changie_latest.outputs.output }}" >> $GITHUB_OUTPUT
build:
needs: [detect-pr, setup]
runs-on: ubuntu-latest
strategy:
matrix:
platform:
- x86_64-linux-musl
- aarch64-linux-musl
- aarch64-apple-darwin
env:
PR_NUMBER: ${{ needs.detect-pr.outputs.pr_number }}
steps:
- uses: actions/checkout@v4
- name: patch shard.yml version
env:
DRIFT_VERSION: ${{ needs.setup.outputs.version }}
run: |
sed -i "s/^version: .*/version: $DRIFT_VERSION/" shard.yml
- uses: docker://ghcr.io/luislavena/hydrofoil-crystal:1.16
with:
args: sh -c "shards check || shards install --skip-postinstall --skip-executables"
- name: Build for ${{ matrix.platform }}
uses: docker://ghcr.io/luislavena/crystal-xbuild:tip
with:
entrypoint: xbuild
args: src/cli.cr drift ${{ matrix.platform }}
- name: Create tarball
run: |
tar -czf drift-pr-${{ env.PR_NUMBER }}-${{ matrix.platform }}.tar.gz -C build/${{ matrix.platform }} drift
- name: Upload tarball artifact
uses: actions/upload-artifact@v4
with:
name: pr-binary-${{ matrix.platform }}
path: |
drift-pr-${{ env.PR_NUMBER }}-${{ matrix.platform }}.tar.gz
comment:
needs: [detect-pr, build]
runs-on: ubuntu-latest
permissions:
pull-requests: write
env:
PR_NUMBER: ${{ needs.detect-pr.outputs.pr_number }}
steps:
- name: Post PR comment
uses: actions/github-script@v7
with:
script: |
const prNumber = process.env.PR_NUMBER;
const runId = context.runId;
const sha = context.sha.substring(0, 7);
const actor = context.actor;
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
const platforms = [
'x86_64-linux-musl',
'aarch64-linux-musl',
'aarch64-apple-darwin'
];
const downloadLinks = platforms.map(platform => {
const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
return `- [${platform}](${artifactUrl}) - \`drift-pr-${prNumber}-${platform}.tar.gz\``;
}).join('\n');
const comment = `## Preview Binaries - Build #${context.runNumber}
Built from commit \`${sha}\` by @${actor}
**Downloads:**
${downloadLinks}
**Note:** These artifacts will expire in 90 days. [View build logs](${runUrl})`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: comment
});