Skip to content

"No api token was provided." error on pull requests from forked repo #128

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

Closed
ianychoi opened this issue Aug 12, 2020 · 9 comments
Closed

Comments

@ianychoi
Copy link

ianychoi commented Aug 12, 2020

  • Bug report: I encounter "No api token was provided." error on Build And Deploy job when I make a pull request from my forked repository. azure_static_web_apps_api_token part has not been interpret. Full logs are below:

  • Question 1: Is it related with Default behavior for PR builds from forks fails  #1 ?

  • Question 2: If the repo does not contain any api stuff, is there some way not to use api token functionality? For example, I tried to specify a dummy value on azure_static_web_apps_api_token as "AZURE_STATIC_WEB_APPS_API_TOKEN" but it generated "An invalid api token was provided." error. It would be also a good idea if a dummy special value (e.g., "DISABLE_API") is specified or an additional option (e.g., "is_api_use: false") is suggested to skip for api stuffs to trigger as optional (note: commenting api_location like "#api_location" didn't help not to show such an error unfortunately).

Build And Deploy 5s
15
Exiting
1
Run Azure/[email protected]
2
  with:
3
    repo_token: ***
4
    action: upload
5
    app_location: /
6
    api_location: api
7
    app_artifact_location: doc/build/html
8
/usr/bin/docker run --name cb09cf54574e284c3cb9e37f03ab8fbaa6_71713a --label 8118cb --workdir /github/workspace --rm -e INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN -e INPUT_REPO_TOKEN -e INPUT_ACTION -e INPUT_APP_LOCATION -e INPUT_API_LOCATION -e INPUT_APP_ARTIFACT_LOCATION -e INPUT_API_BUILD_COMMAND -e INPUT_APP_BUILD_COMMAND -e INPUT_ROUTES_LOCATION -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/contributon-2020/contributon-2020":"/github/workspace" 8118cb:09cf54574e284c3cb9e37f03ab8fbaa6
9
DeploymentId: 669d00e8-fb89-4d51-94ed-ba18a5745a45
10

11
No api token was provided.
12

13
For further information, please visit the Azure Static Web Apps documentation at https://docs.microsoft.com/en-us/azure/static-web-apps/
14
If you believe this behavior is unexpected, please raise a Github issue at https://github.com/azure/static-web-apps/issues/
15
Exiting

On the other hand, I see that it works well when I make a pull request from one branch to another on the same repo or there is a new commit on the repository. Please compare with the below log:

/usr/bin/docker run --name cbdcaa1a25bf7f4553a92c9efd1a2d6ce9_07866d --label 8118cb --workdir /github/workspace --rm -e INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN -e INPUT_REPO_TOKEN -e INPUT_ACTION -e INPUT_APP_LOCATION -e INPUT_API_LOCATION -e INPUT_APP_ARTIFACT_LOCATION -e INPUT_API_BUILD_COMMAND -e INPUT_APP_BUILD_COMMAND -e INPUT_ROUTES_LOCATION -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/contributon-2020/contributon-2020":"/github/workspace" 8118cb:dcaa1a25bf7f4553a92c9efd1a2d6ce9
10
DeploymentId: 44853027-87ec-4333-8aad-e8ea15b06b1d
11

12
App Directory Location: '/' was found.
13
[WARNING] Api Directory Location: 'api' could not be found. Azure Functions will not be created.
14
Starting to build app with Oryx
15
Azure Static Web Apps utilizes Oryx to build both static applications and Azure Functions. You can find more details on Oryx here: https://github.com/microsoft/Oryx
16
---Oryx build logs---
17

18

19
Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx
20
You can report issues at https://github.com/Microsoft/Oryx/issues


...


Removing existing manifest file
97
Creating a manifest file...
98
Manifest file created.
99

100
Done in 15 sec(s).
101

102

103
---End of Oryx build logs---
104
Finished building app with Oryx
105
Zipping App Artifacts
106
Done Zipping App Artifacts
107
Either no Api directory was specified, or the specified directory was not found. Azure Functions will not be created.
108
Uploading build artifacts.
109
Finished Upload. Polling on deployment.
110
Status: InProgress. Time: 0.0899183(s)
111
Status: Succeeded. Time: 15.1601066(s)
112
Deployment Complete :)
113
Visit your site at: https://green-river-0b49fad1e-6.westus2.azurestaticapps.net
114
Thanks for using Azure Static Web Apps!
115
Exiting
@miwebst
Copy link
Contributor

miwebst commented Aug 12, 2020

Ah so this is the same as #1, and the api's here are actually referring to 2 different things. I see thats confusing!

So the api token its complaining about is the api token used to validate the Github Action with the content servers. This is added to your repo when you create the static web apps resource. When you fork a repo it does not copy the api token as well which is why you are seeing the error.

Whether your project contains an Azure Functions backend (the api folder the logs are talking about) wont affect whether the token is present or not.

We dont have a Portal experience around this today, but you can get your api token and manually add it to your Github repo as a secret, then you can use that secret in the workflow for your forked repo.

cc @ehamai as this is something we should discuss adding

@miwebst
Copy link
Contributor

miwebst commented Aug 25, 2020

Actually check out: #131

Looks like Github Actions now allows this behavior, we have a fix coming out to handle this case. I'll post back here when it is out!

@alphabt
Copy link

alphabt commented Aug 31, 2020

@miwebst Could you point me to resources on how to manually get the api token? I forked a repo and now I'm running into this issue during deploy, but couldn't find out how to get the token.

@miwebst
Copy link
Contributor

miwebst commented Aug 31, 2020

The fix is actually out for this (as of a few hours ago), is this behavior still happening?

@MaxOSchulte
Copy link

Same here, just forked a repo and added a new static website in Azure. The connection is fine, i'm searching for the API token

@miwebst
Copy link
Contributor

miwebst commented Sep 4, 2020

So just to clarify, are you forking a repository and then creating a static web app against the newly forked repo?

@MaxOSchulte
Copy link

Yes. The solution for me was to delete the .github/workflows folder and recreate the static web app

@miwebst
Copy link
Contributor

miwebst commented Sep 8, 2020

This is a slightly different scenario than above. If you fork a repository you will also copy over any GitHub Action workflow files with it. Our GitHub Action wont work correctly without a secret for deployment. This secret is stored in your repository secrets which wont be present on the forked repository so the action will always fail. Cleaning up the workflow file and recreating the Static Web App is probably the easiest thing to do.

If your workflow had a lot of configurations and you wanted to save them, there is a way to create the Static Web App without modifying the workflow file or referenced secrets, but there is no UI experience for this today.

@miwebst
Copy link
Contributor

miwebst commented Sep 14, 2020

Closing this as the initial problem is now fixed, you can create a staging environment by creating a pull request from a forked repo.

@miwebst miwebst closed this as completed Sep 14, 2020
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

No branches or pull requests

4 participants