Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action still runs a build step even when it's skipped #34

Closed
cswilliams opened this issue Jan 28, 2025 · 2 comments
Closed

Action still runs a build step even when it's skipped #34

cswilliams opened this issue Jan 28, 2025 · 2 comments

Comments

@cswilliams
Copy link

I have a common deployment workflow shared across both my staging and production environments with an if condition so it only triggers for production deployments:

  - name: Notify Rollbar of deployment
    continue-on-error: true
    uses: rollbar/github-deploy-action@eaf2a60ea238bd273226eee0ddceecfe5611964d # 2.1.2
    if: ${{ inputs.environment == 'production' }}

However, I noticed for my staging deployments, the action is still running a build / setup step at the start of my workflow that takes about 5 seconds:

Build container for action use: '/home/runner/work/_actions/rollbar/github-deploy-action/eaf2a60ea238bd273226eee0ddceecfe5611964d/Dockerfile'

I've been trying to get my deployments around a minute so this actually accounts for 5% of my total deployment time.

Is there a better way to skip this action for different environments or make the action smarter so it doesn't run this when it's being skipped?

Thanks

@brianr
Copy link
Member

brianr commented Feb 26, 2025

@cswilliams thanks for the question!

From researching this a bit, it seems that in GitHub Actions, the container for the job (in this case Notify Rollbar of deployment) is built even if the step inside the job is eventually skipped via an if: check. But, a workaround is to wrap it inside another job, like this:

name: Deploy

on:
  workflow_dispatch:
    inputs:
      environment:
        description: "Deployment environment"
        required: true
        default: "staging"

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Check environment
        run: echo "Deploying to ${{ github.event.inputs.environment }}"

      - name: Actual build/deploy steps
        run: echo "Building and deploying..."

  notify-rollbar:
    # `needs` ensures this job won't run until after `build-and-deploy` completes
    needs: build-and-deploy
    # `if` ensures the entire job is skipped if environment is not production
    if: ${{ github.event.inputs.environment == 'production' }}
    runs-on: ubuntu-latest
    steps:
      - name: Notify Rollbar of deployment
        uses: rollbar/github-deploy-action@eaf2a60ea238bd273226eee0ddceecfe5611964d
        with:
          accessToken: ${{ secrets.ROLLBAR_ACCESS_TOKEN }}
          environment: production

Does this solve your issue?

@cswilliams
Copy link
Author

Ahh, interesting, that's a great workaround. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants