Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit cf8ee19

Browse files
committed
Fix Netflify builds from fork PRs
Some absolutely horrenous hacks to upload the context as an artifact then download it, unzip it and set the PR number as a variable we can use, because GitHub Actions just doesn't offer any other way of doing this. Maybe we'd be better off going back to Netlify...
1 parent eadc940 commit cf8ee19

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

.github/workflows/layered-build.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,16 @@ jobs:
1616
path: element-web/webapp
1717
# We'll only use this in a triggered job, then we're done with it
1818
retention-days: 1
19+
- uses: actions/[email protected]
20+
with:
21+
script: |
22+
var fs = require('fs');
23+
fs.writeFileSync('${{github.workspace}}/context.json', JSON.stringify(context));
24+
- name: Upload Context
25+
uses: actions/upload-artifact@v2
26+
with:
27+
name: context.json
28+
path: context.json
29+
# We'll only use this in a triggered job, then we're done with it
30+
retention-days: 1
1931

.github/workflows/netflify.yaml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,28 @@ jobs:
3333
});
3434
var fs = require('fs');
3535
fs.writeFileSync('${{github.workspace}}/previewbuild.zip', Buffer.from(download.data));
36-
- run: unzip previewbuild.zip && rm previewbuild.zip
36+
37+
var contextArtifact = artifacts.data.artifacts.filter((artifact) => {
38+
return artifact.name == "context.json"
39+
})[0];
40+
var download = await github.actions.downloadArtifact({
41+
owner: context.repo.owner,
42+
repo: context.repo.repo,
43+
artifact_id: contextArtifact.id,
44+
archive_format: 'zip',
45+
});
46+
var fs = require('fs');
47+
fs.writeFileSync('${{github.workspace}}/context.json.zip', Buffer.from(download.data));
48+
- name: Extract Artifacts
49+
run: unzip -d webapp previewbuild.zip && rm previewbuild.zip && unzip context.json && rm context.json.zip
50+
- name: 'Read Context'
51+
id: readctx
52+
uses: actions/[email protected]
53+
with:
54+
script: |
55+
var fs = require('fs');
56+
var ctx = JSON.parse(fs.readFileSync('${{github.workspace}}/context.json'));
57+
console.log(`::set-output name=prnumber::${ctx.payload.pull_request.number}`);
3758
- name: Deploy to Netlify
3859
id: netlify
3960
uses: nwtgck/[email protected]
@@ -51,7 +72,7 @@ jobs:
5172
uses: phulsechinmay/[email protected]
5273
with:
5374
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54-
ISSUE_ID: ${{ github.event.workflow_run.pull_requests[0].number }}
75+
ISSUE_ID: ${{ steps.readctx.outputs.prnumber }}
5576
message: |
5677
Preview: ${{ steps.netlify.outputs.deploy-url }}
5778
⚠️ Do you trust the author of this PR? Maybe this build will steal your keys or give you malware. Exercise caution. Use test accounts.

0 commit comments

Comments
 (0)