1

I’m facing an issue with my GitHub Actions CI/CD setup for deploying a web app to Firebase Hosting. I’ve set up three workflows:

Pull Request Workflow: Validates code on PR creation. Build Workflow: Generates the build artifact (uploads build folder). Deploy Workflow: Deploys to Firebase Hosting, triggered via workflow_run after a successful build.

The workflows run in order, and the run-id matches between Build and Deploy (e.g., 1632955673). The Build workflow successfully uploads the build artifact, but the Deploy workflow fails with "Unable to download artifact(s): Artifact not found for name: build" and logs show "artifacts": []. This breaks the deployment.

What We’ve Tried:

  • Confirmed run-id consistency via debug logs.
  • Added retention-days: 7 to Upload Build Artifact.
  • Updated Download Build Artifact with run-id: ${{ github.event.workflow_run.id }} to target the Build run.
  • Enhanced debugging with ls -la to verify the build folder post-upload.
name: Firebase Deployment Build
on:
  push:
    branches:
      - master
jobs:
  build:
    name: Generate Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
      - name: Install Dependencies
        run: npm install --legacy-peer-deps
      - name: Build
        env:
          CI: false
        run: npm run build
      - name: Verify Build Directory
        run: ls -la || echo "Build directory not found"
      - name: Upload Build Artifact
        uses: actions/upload-artifact@v4
        with:
          name: build
          path: build
      - name: Confirm Artifact Upload
        run: echo "Artifact upload completed"
      - name: Log Build Run ID
        run: echo "Build Run ID - ${{ github.run_id }}"
name: Deploy to Firebase Hosting on successful build
'on':
  workflow_run:
    workflows: [Firebase Deployment Build]
    types:
      - completed
jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4
      - name: Debug Workflow Context
        run: |
          echo "Triggering Workflow Run ID: ${{ github.event.workflow_run.id }}"
          echo "Triggering Workflow Name: ${{ github.event.workflow_run.name }}"
          echo "Triggering Workflow Conclusion: ${{ github.event.workflow_run.conclusion }}"
      - name: Download Build Artifact
        uses: actions/download-artifact@v4
        with:
          name: build
          path: build
      - name: Verify Downloaded Artifact
        run: ls -la build || echo "Build artifact not found after download"
      - name: Debug Deployment Directory
        run: |
          echo "Current directory contents:"
          ls -la
          echo "Build directory contents:"
          ls -la build || echo "Build directory not found"
      - name: Deploy to Firebase
        uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: ${{ secrets.GITHUB_TOKEN }}
          firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
          channelId: live
          projectId: tabrez-portfolio-2

I’ve some CI/CD knowledge, managing this pipeline myself. I spent late night refactoring deprecated Firebase Hosting methods (e.g., switching from tokens to service accounts), and this last hurdle is keeping me from peace. I’d love input from DevOps experts or those who’ve tackled similar Firebase deployment issues.

Question: Why is the artifact array empty despite a successful upload? Any misconfigurations or alternative approaches to ensure artifact availability across workflows?

3
  • Can you try using a custom token as specified in Download Artifacts from other Workflow Runs or Repositories? Despite the run ID being the same, I am not sure whether the token is valid for the other workflow. Commented Jul 17 at 19:08
  • Also, is the ${{ github.run_id }} actually the same if you print ${{ github.run_id }} in the second workflow? If not, you'd probably want to add ${{ github.event.workflow_run.id }} as the run ID for actions/download-artifact. Commented Jul 17 at 19:09
  • Thanks, @dan1st! The URL solution with github.event.workflow_run.artifacts_url worked after adding some permissions, but it required extensive code in the Deploy workflow. Permissions Granted: permissions: actions: read contents: read Earlier, I had combined the Build and Deploy into a single workflow, which was working smoothly but I wanted to keep separate workflows. Commented Jul 19 at 9:53

2 Answers 2

0

Please, consider adding some inputs to the upload action:

      - name: 📦 Upload Build Artifact
        uses: actions/upload-artifact@v4
        with:
          path: build
          name: build
          retention-days: 1
          include-hidden-files: true
          if-no-files-found: error

I also usually add a prefix to the artifact name, like the following:

env:
  ARTIFACTS_PREFIX: wf-${{ github.workflow_sha }}-${{ github.run_number }}
      - name: 📦 Upload Build Artifact
        uses: actions/upload-artifact@v4
        with:
          path: build
          name: ${{ env.ARTIFACTS_PREFIX }}_build
          retention-days: 1
          include-hidden-files: true
          if-no-files-found: error
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Francesco, for the ARTIFACTS_PREFIX suggestion. I updated main.yml with name: ${{ env.ARTIFACTS_PREFIX }}_build and env: ARTIFACTS_PREFIX: wf-${{ github.workflow_sha }}-${{ github.run_number }}, it failed then I updated build name in firebase-hosting-merge.yml with name: ${{ format('wf-{0}-{1}_build', github.event.workflow_run.sha, github.event.workflow_run.run_number) }}. Still fails with "Artifact not found" and "artifacts": [].
0

A suggestion from @dan1st to use github.event.workflow_run.artifacts_url to fetch artifacts via the GitHub API, here are the updated files with the required changes. The Deploy workflow will now use a script to download the artifact dynamically, replacing the failing Download Build Artifact step.


name: Deploy to Firebase Hosting on successful build
'on':
  workflow_run:
    workflows: [Firebase Deployment Build]
    types:
      - completed
jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    permissions:
      actions: read  # Added to fix 403 error
      contents: read  # Added to allow repository checkout
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}  # Explicitly pass the token
          repository: tabrezdal/my-portfolio-2.0  # Ensure correct repo
      - name: Debug Workflow Context
        run: |
          echo "Triggering Workflow Run ID: ${{ github.event.workflow_run.id }}"
          echo "Triggering Workflow Name: ${{ github.event.workflow_run.name }}"
          echo "Triggering Workflow Conclusion: ${{ github.event.workflow_run.conclusion }}"
      - name: Install jq
        run: sudo apt-get update && sudo apt-get install -y jq
      - name: Fetch and Download Artifacts
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          # Get the artifacts URL from the workflow_run event
          ARTIFACTS_URL="${{ github.event.workflow_run.artifacts_url }}"
          echo "Artifacts URL: $ARTIFACTS_URL"

          # Use GitHub API to list artifacts
          ARTIFACTS=$(curl -L -H "Authorization: token $GITHUB_TOKEN" "$ARTIFACTS_URL")
          echo "Artifacts: $ARTIFACTS"

          # Extract the artifact name (assuming 'build' as the name)
          ARTIFACT_NAME=$(echo "$ARTIFACTS" | jq -r '.artifacts[0].name' || echo "build")
          echo "Artifact Name: $ARTIFACT_NAME"

          # Download the artifact using the GitHub API
          DOWNLOAD_URL=$(echo "$ARTIFACTS" | jq -r '.artifacts[0].archive_download_url')
          if [ -z "$DOWNLOAD_URL" ]; then
            echo "No download URL found, artifact may not exist or access is denied."
            exit 1
          fi
          curl -L -H "Authorization: token $GITHUB_TOKEN" -o artifact.zip "$DOWNLOAD_URL"
          unzip artifact.zip -d build
          rm artifact.zip
      - name: Verify Downloaded Artifact
        run: ls -la build || echo "Build artifact not found after download"
      - name: Debug Deployment Directory
        run: |
          echo "Current directory contents:"
          ls -la
          echo "Build directory contents:"
          ls -la build || echo "Build directory not found"
      - name: Deploy to Firebase
        uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: ${{ secrets.GITHUB_TOKEN }}
          firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
          channelId: live
          projectId: tabrez-portfolio-2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.