Skip to content

🚀 Publish previews on netlify#1088

Closed
afranke wants to merge 5 commits into
masterfrom
netlify-previews
Closed

🚀 Publish previews on netlify#1088
afranke wants to merge 5 commits into
masterfrom
netlify-previews

Conversation

@afranke
Copy link
Copy Markdown
Contributor

@afranke afranke commented Oct 5, 2021

This should publish a preview on netlify for every Actions run, with a link to it.

Signed-off-by: Alexandre Franke <alexandre.franke@matrix.org>
@afranke
Copy link
Copy Markdown
Contributor Author

afranke commented Oct 5, 2021

The second workflow will only be run if the file is in the default branch, so we can’t rely on this PR to check whether it works correctly. The changes to the build workflow have not broken it. @richvdh do you reckon I can merge this and fix it afterwards if it turns out not to work as expected?

@afranke afranke requested a review from richvdh October 5, 2021 14:26
Copy link
Copy Markdown
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we not need to inhibit the netlify upload for non-PR builds?

with:
script: |
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.json', JSON.stringify(context.payload.pull_request));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how will this behave for builds not associated with a PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this will fail because prInfoArtifact.id is not defined (https://github.com/matrix-org/matrix-react-sdk/runs/3805077607?check_suite_focus=true would be an example of that).

We should probably handle this more gracefully.

There is no way to exit a job early, so that means that after the script step we would need to have an if for every subsequent step. Not great (but not necessarily an issue, just something to be aware of).

If on.workflow_run.branches-ignore does not exist and work, I reckon we have to run the script step in all cases as I don’t see a way to determine whether there was a PR before we try to download the PR metadata artifact.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misread the code this was referring to and thought we were talking about the script step of the netlify.yml workflow. Will read the documentation further.

Comment on lines +13 to +15
# There's a 'download artifact' action but it hasn't been updated for the
# workflow_run action (https://github.com/actions/download-artifact/issues/60)
# so instead we get this mess:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be easier just to put these steps in the other workflow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do that and for some reason netlify fails, then the build workflow status won’t be success.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well yes, but how much is that really a problem?

Comment thread .github/workflows/netlify.yml Outdated
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's something weird going on with the indentation here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed.

Comment thread .github/workflows/netlify.yml Outdated
Comment thread .github/workflows/netlify.yml Outdated
Comment on lines +20 to +47
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "merged-content-artifact"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/content.zip', Buffer.from(download.data));

var prInfoArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr.json"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: prInfoArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.json.zip', Buffer.from(download.data));
Copy link
Copy Markdown
Member

@richvdh richvdh Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we really need this stuff.. maybe we should write our own action for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, although the ideal scenario really would be for the download-artifact action to be fixed, as pointed out by the comment. This comes from matrix-react-sdk BTW.

Can we consider this out of scope for this PR though?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, although the ideal scenario really would be for the download-artifact action to be fixed, as pointed out by the comment.

Sure, but given the issue has been open a year with no reply from the maintainers, let's not hold our breath on that one.

This comes from matrix-react-sdk BTW.

ok, so this is at least our second copy of it!

Can we consider this out of scope for this PR though?

I guess so. I do think we should do something else before we make a third copy.

My understanding is that once you've got the javascript, writing an action is pretty easy.

Alexandre Franke added 4 commits October 5, 2021 18:06
Signed-off-by: Alexandre Franke <alexandre.franke@matrix.org>
Signed-off-by: Alexandre Franke <alexandre.franke@matrix.org>
Signed-off-by: Alexandre Franke <alexandre.franke@matrix.org>
Signed-off-by: Alexandre Franke <alexandre.franke@matrix.org>
@afranke
Copy link
Copy Markdown
Contributor Author

afranke commented Oct 5, 2021

do we not need to inhibit the netlify upload for non-PR builds?

I would love to. I really can’t tell from the GHA documentation whether it’s possible though.

There is no documented on.workflow_run.branches-ignore as far I can see, only on.<push|pull_request>.branches-ignore but then the examples for workflow_run use branches which is not documented either. Shall I just try to use on.workflow_run.branches-ignore and 🤞 ?

@afranke
Copy link
Copy Markdown
Contributor Author

afranke commented Oct 5, 2021

Considering the concerns that were raised here (and which I share), I’ll write another version of this that does everything in the initial workflow. I will do it on a different branch and open a new PR, and we can decide which one to run with once we have both.

@afranke
Copy link
Copy Markdown
Contributor Author

afranke commented Oct 6, 2021

We went with #1089 instead.

@afranke afranke closed this Oct 6, 2021
@afranke afranke deleted the netlify-previews branch December 28, 2021 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants