Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
332 stars 57 forks source link

GitHub Action: Close PR errors with deployment_token was not provided. #1489

Open Official-James opened 6 months ago

Official-James commented 6 months ago

Describe the bug

Using the azure/static-web-apps-deploy GitHub Action, on closed PR action the following error appears:

deployment_token was not provided.
The deployment_token is required for deploying content. If you'd like to continue the run without deployment, add the configuration skip_deploy_on_missing_secrets set to true in your workflow file
An unknown exception has occurred

This is preventing cleanup of the preview environments in the Static Web App.

To Reproduce Steps to reproduce the behavior:

  1. Add the following as a job in GitHub Actions:

    close_pull_request_job:
    name: Close Pull Request Job
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request' && github.event.action == 'closed'
    
    steps:
      - name: Close Pull Request
        id: closepullrequest
        uses: Azure/static-web-apps-deploy@v1
        with:
            app_location: '.'
            azure_static_web_apps_api_token: ${{ secrets.staticWebAppToken }}
            action: "close"
  2. Close PR to trigger
  3. The above error appears

Expected behavior PR to trigger on close and clean-up the preview environment

PipeItToDevNull commented 5 months ago

https://github.com/Azure/static-web-apps/issues/1342

This is the same issue, but I don't understand the fix

PipeItToDevNull commented 5 months ago

I obtained a token by going to the SWA and choosing "Manage deployment token" on the "Overview" page.

This token is then created as a Dependabot specific secret WITH THE SAME NAME as the normal token per https://github.com/Azure/static-web-apps/issues/788

mikeholczer commented 2 weeks ago

I don't think this is truly a duplicate because this issue exists in the action as created by the wizard for creating a SWA, where as the linked issues I believe relate to actions people manually created.

georgibakken commented 5 days ago

I tried taking the token from Azure Portal, adding it as a Dependabot secret with the name AZURE_STATIC_WEB_APPS_API_TOKEN and setting it in the Close Pull Request Job

    name: Close Pull Request Job
    steps:
      - name: Close Pull Request
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
          action: "close"

with no success, I get the same error deployment_token was not provided.

I have a manually created pipeline

georgibakken commented 5 days ago

It worked for me by setting the token as a normal repository secret, as described here