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