Search code examples
firebaseyamlgithub-actions

Github action to firebase hosting cd preview


I am setting up my first svelte project with vite and it should be hosted on firebase. I made a action that deploys to firebase, that works just fine. However i made a similar github action that generates a preview channel on pull request that is not working.

This is my code.

name: Deploy to Preview Channel

on:
  pull_request_target:
jobs:
  build_and_preview:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: npm install
      - run: npm run build

      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: "${{ secrets.GITHUB_TOKEN }}"
          firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_SVELTE_WETHER_SITE }}"
          expires: 10d
          projectId: your-Firebase-project-ID

and this is the error i get

Run FirebaseExtended/action-hosting-deploy@v0
/home/runner/work/_actions/FirebaseExtended/action-hosting-deploy/v0/bin/action.min.js:3759
                const error = new RequestError(message, status, {
                              ^

RequestError [HttpError]: Resource not accessible by integration
    at /home/runner/work/_actions/FirebaseExtended/action-hosting-deploy/v0/bin/action.min.js:3759:31
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async createCheck (/home/runner/work/_actions/FirebaseExtended/action-hosting-deploy/v0/bin/action.min.js:5680:17)
    at async run (/home/runner/work/_actions/FirebaseExtended/action-hosting-deploy/v0/bin/action.min.js:11435:14) {
  status: 403,

i have tryed to use both on: pull_request_target: and on: pull_request: as i read somewhere that the secret might not have acces to the key otherwise


Solution

  • This occurs due to the restrictions on read/write permission for workflows. Follow these steps to solve this.

    1. Go to your repository Settings
    2. Click Actions and then click General
    3. Scroll to Workflow Permission Section
    4. Mark the 'Read and Write Permissions'

    Workflow Permissions

    Note: if you are in a Github Organization, you must change this setting at the organization level first, otherwise this option will be greyed out.