FirebaseExtended / action-hosting-deploy

Automatically deploy shareable previews for your Firebase Hosting sites
https://firebase.google.com/docs/hosting/github-integration
Apache License 2.0
704 stars 202 forks source link

[BUG] #320

Closed christopher-aldred closed 11 months ago

christopher-aldred commented 11 months ago

Action config

name: Deploy to PREVIEW on pull request
"on": pull_request_target
jobs:
  build_and_preview:
    permissions: write-all
    if: "${{ github.event.pull_request.head.repo.full_name == github.repository }}"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Build application
        run: npm ci && npm run build
      - name: Deploy to firebase PREVIEW
        uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: "${{ secrets.GITHUB_TOKEN }}"
          firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_LEADER_BOARD_APP }}"
          projectId: leader-board-app

Expected behavior

When creating a PR the preview channel should contain the application built using the code in the PR.

Actual behavior

The preview channel appears identical to the PROD/live channel. I think it maybe be using the main branch rather than the PR. So merging from develop to main it should be building and deploying the develop branch not the main.

oyvindwe commented 11 months ago

We use "on": pull_request - try that?

christopher-aldred commented 11 months ago

Pull_request and pull_request_target are essentially the same but the latter has access to github tokens.

I fixed it with the following:

name: Deploy to PREVIEW
"on": pull_request_target
jobs:
  build_and_preview:
    permissions: write-all
    if: "${{ github.event.pull_request.head.repo.full_name == github.repository }}"
    runs-on: ubuntu-latest
    steps:
      - name: Checking out PR code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          ref: ${{ github.event.pull_request.head.sha }}
          repository: ${{github.event.pull_request.head.repo.full_name}}