-
Notifications
You must be signed in to change notification settings - Fork 59
Default behavior for PR builds from forks fails #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We are planning to consider build and pass the PR without deployment as future behavior. Pre-production environments are limited and auto-deployment in this scenario may not be what the app owner intends in all cases. |
What if we do want to auto deploy those? |
Hi folks, pretty advanced GitHub Actions user here. Now that we can have microsoft repos use SWA, I got it running for TypeScript. I have it set up to deploy for on an open source repo for external PRs, but I need to find a way to get the URL back into my PR. Here's what I originally did:
This hit the 'public repos' don't get secrets issue. Which is fine, because Here's how it works: Now, my CI builds an artifact of the static site on CI instead of deploying. That artifact is passed to a This allows an OSS repo to get contribution PRs which trigger the upload. Doing it this way doesn't get the message back in the comment thread however, but it does upload So my request is that the GitHub Action sets an output of the URL, then I can have all sorts of ways of grabbing the URL and presenting it to users. ( I built danger-js for this use-case a few years ago. ) If someone reaches out to me on MS teams, to let me know where code lives - I can help ship that code get that to work. Otherwise I'll look around and see if there are APIs I can use to find the URL like |
@orta that's awesome! |
@orta this is super cool! Having the url as an output is something a lot of folks have asked for especially for performing tests after deployment. The challenge for us is that we run inside a Docker based Github Action. Do you know of anyway to set the output for the action when using Docker based actions? |
I do, the way it works is that GH listens to specially crafted stdout messages from your action to determine outputs. I'll assume bash (for my familiarity), but realistically it can be anything: echo “::set-output name=<output name>::<value>” e.g. echo “::set-output name=static_web_app_deploy_url::https://nice-meadow-0c9756810.azurestaticapps.net” Would let me pick that up in another workflow step, there's some docs here with sample code here |
Small update, we did get a working prototype of this! Thanks for the help. I will followup once we've finished testing and released it. |
This is now in production, you can access the build and deploy output like so:
|
Thanks! |
👋🏻 - I've been working on a sample repo which shows the OSS PR process. Here's how it works so far, and then after, why it's not working yet. Repo: https://github.com/orta/pr-builds-static-web-apps ( I'd open ^ in a new window to run along-side this comment, they're well commented ) The ProblemA cross-fork PR does not get the access token to push to azure. The token is a secret, and secrets aren't shared to fork PRs, which is a reasonable security measure by GitHub on GH Actions. Other static site providers like next/gatsby/etc will build the PR builds themselves, and don't have this problem. Because SWA build happens on GH Actions, then the security model of GH Actions affects PR builds. The SolutionUse the new So, we pass the built version of the site and some PR metadata to a The Process
You can see a working PR here: orta/pr-builds-static-web-apps#5 What Doesn't WorkIt only uploads to the 'master' environment, I've tried using a custom branch and pushing that but I think the dockerfile makes assumptions that it is being ran in a PR workflow and I'd need some args which let me define the environment I wondered if it was tied to the current branch, so I explored running that action when the other PR was checked out but that didn't work. Potential Solutions
# Uploads the static build
- name: Build And Deploy
uses: Azure/[email protected]
id: deploy
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ICY_MOSS_0DAC87810 }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: "upload"
app_location: "built"
app_artifact_location: "public"
environment: "pr_${{ steps.pr_info.outputs.number }}" or the PR meta could be manually added instead: # Uploads the static build
- name: Build And Deploy
uses: Azure/[email protected]
id: deploy
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ICY_MOSS_0DAC87810 }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: "upload"
app_location: "built"
app_artifact_location: "public"
repo: ${{ steps.pr_info.outputs.number }}
pull_number: ${{ steps.pr_info.outputs.number }} This would let this technique work, but dang the whole thing a bit unfriendly and requires quite a lot of knowledge about how GH Actions works for something which I think someone would expect to kinda work out of the box.
|
Hello there, @orta proposed solution (capturing the artifact and using Some alternative ideas:
I haven't tested them yet, but I can dedicate some time trying something if asked :). |
It seems like the workaround that @orta proposed is now possible via |
A very common scenario is people outside the repo contributing PR's. The current default Actions template fails the PR since the secrets aren't available.
At the very least, it should still build but then pass the PR without doing any deploy.
This should be fixed soon or people who try it out may quickly get frustrated and remove it since all their PR's fail.
The text was updated successfully, but these errors were encountered: