Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Check if object is empty in GitHub Actions workflow

I'm running a test using a GitHub Actions workflow, and I would like to fail the test if the resulting object produced by the test is empty. How do I check if a JSON object is empty?

My current workflow job contains the step:

- name: Fail if security tests found any issues
  if: ${{ steps.securityTestsResults != {} }}
  uses: actions/github-script@v3
  with:
    script: |
        core.setFailed('security tests failed: non-empty results')

But the code above currently results in the error:

Invalid workflow file : .github/workflows/securityTests.yml#L34
The workflow is not valid. .github/workflows/securityTests.yml (Line: 34, Col: 11): Unexpected symbol: '{}'. Located at position 31 within expression: steps.securityTestsResults != {} 

It's confusing since I believe my code would work in regular javascript, but it doesn't appear to work here. I've also tried Object.keys(obj).length === 0 and JSON.stringify(obj) == '{}' but these don't work either (it doesn't recognize the Object or JSON classes).

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try toJSON:

if: toJSON(steps.securityTestsResults) == "{}"

(You don't need the wrapping ${{ }} in an if statement, as they're always evaluated as expressions.)

Docs: https://docs.github.com/en/actions/learn-github-actions/expressions#tojson

about 4 years ago · Juan Pablo Isaza Relatório

0

- name: Check HOST ENV
   uses: actions/github-script@v4
   with:
    script: |
      if( "${{env.HOST}}" == "ERR" ){
        core.setFailed('Error mnj')
      }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda