Netlify auto-deploys before GitHub action has finished updating the code

Netlify site name: visma-rating.netlify.app

I am running semantic-release in a github action when something is pushed to main. Semantic-release updates the package.json version number and creates a changelog.md, but netlify auto deploys the site before semantic-release is finished updating files. The result is a prod site with a wrong version number.

Is there anything I can do to delay auto-deploy until my script has finished?

Okay, then I tried another solution - “Build settings → Stop builds” and then call netlify-cli after semantic-release in my github action. That did not work either :angry:

It didn’t work because instead of deploying it, it write this in the log:

◈ Deployments are "locked" for production context of this site

? Would you like to "unlock" deployments for production context to proceed? (y/N) 
Error: Process completed with exit code 130.

It’s kind of difficult to answer when it is part of an automated script :cry:

So now I’m stuck, none of my solutions works. What do I do now? Please HELP!

My github action:

name: release
on:
  push:
    branches:
      - main

jobs:
  release:
    name: Release
      ...
      - name: Deploy Site
        env:
          NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
          NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
        run: npm run netlify -- deploy --dir=dist --prod

Can you replace the lines starting from

with the following & let me know whether it worked ?

      - name: Deploy to netlify
        uses: netlify/actions/cli@master
        env:
          NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
          NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
        with:
          args: deploy --dir=build --prod
          secrets: '["NETLIFY_AUTH_TOKEN", "NETLIFY_SITE_ID"]'

I got it to work by disabling Netlify in GitHub apps. That way I can enable set “Active builds” in Netlify, and my deploy work with:

- name: Deploy Site
        env:
          NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
          NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
        run: npx netlify-cli deploy --dir=dist --prodIfUnlocked

But it also means that auto preview and netlifybot are no longer working. So not the best solution, but it works for now.

A better solution will be a --force flag on netlify-cli deploy, which forces deploy to prod even if it is locked.

1 Like

Thanks for coming back and letting us know you got this working!