Standard Github actions for pull request

Hi,

So im trying to have qovery run for specific github pull requests. I use the CLI to run clone → app update → deploy which works fine,

but then if someone updates the PR the job fails due clone saying that an environment already exists with that name.

HOw do you deal with running the GHA mutiple times? (i put in a 'if: {{ !cabcekked()}} on the app update and deploy but it shows the job as failed still.

Hi @Stephen_Bennett , Could you share your GitHub Actions with me?

But basically, it’s up to you in that case to properly check actions that you are running if the Pull Request is updated. Maybe you could add a check if the environment XXX exists, then you update the apps you just redeploy the apps with the new changes.

If I got access to your GitHub Actions yaml, I can take a deeper look and propose a solution :slight_smile:

name: "qovery - clone"

permissions:
  actions: write
  checks: write
  contents: write
  deployments: write
  id-token: write
  issues: write
  discussions: write
  packages: write
  pages: write
  pull-requests: write
  repository-projects: write
  security-events: write
  statuses: write

on:
  pull_request:
    branches: [ master ]
  workflow_dispatch:
jobs:
  qovery-clone:
    # check Pull request has a ridp label (If not dont create a environment)
    if: >-
        contains(github.event.pull_request.labels.*.name, 'idp')
    runs-on: ubuntu-latest
    steps:
      - name: check out
        uses: actions/checkout@v3

      - name: Extract branch name
        shell: bash
        run: |
          branch=$(echo "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" | tr '[:upper:]' '[:lower:]')
          echo "branch=$branch" >> "$GITHUB_OUTPUT"
        id: extract_branch

      - name: Qovery Install
        run: |
          curl -s https://get.qovery.com | bash
        env:
          QOVERY_CLI_ACCESS_TOKEN: ${{ secrets.QOVERY }}

      - name: Qovery Clone
        run: |
          qovery environment clone \
          --organization "x" \
          --project "x" \
          --environment "entity-store" \
          --new-environment-name ${{ steps.extract_branch.outputs.branch }}
        env:
          QOVERY_CLI_ACCESS_TOKEN: ${{ secrets.QOVERY }}

      # No matter what, we want to make sure the branchs are updated!
      - name: Qovery Branch Update Terraform
        run: |
          qovery lifecycle update \
          --organization "x" \
          --project "x" \
          --environment ${{ steps.extract_branch.outputs.branch }} \
          --lifecycle "Entity Store - Terraform" \
          --branch $GITHUB_HEAD_REF \
        if: ${{ !cancelled() }}
        env:
          QOVERY_CLI_ACCESS_TOKEN: ${{ secrets.QOVERY }}

      - name: Qovery Branch Update Helm
        run: |
          qovery helm update \
          --organization "x" \
          --project "x" \
          --environment ${{ steps.extract_branch.outputs.branch }} \
          --helm "Entity Store - Helm" \
          --chart_git_commit_branch $GITHUB_HEAD_REF
        if: ${{ !cancelled() }}
        env:
          QOVERY_CLI_ACCESS_TOKEN: ${{ secrets.QOVERY }}

      - name: Qovery Deploy
        run: |
          qovery environment deploy \
          --organization "x" \
          --project "x" \
          --environment ${{ steps.extract_branch.outputs.branch }} \
          --watch
        if: ${{ !cancelled() }}
        env:
          QOVERY_CLI_ACCESS_TOKEN: ${{ secrets.QOVERY }}

      - uses: actions/github-script@v6
        with:
          script: |
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: 'Qovery environment deployed go to ingress: ${{ steps.extract_branch.outputs.branch }}-entity-store-api.opencorporates.dev'
            })

switched to

      - name: Qovery Clone
        continue-on-error: true

this lets if carry on to the next step and complete successfully, just seems a bit janky

Something that you could do is this:

# Execute the first command and capture its output
output=$(qovery environment list --json | jq -r '.[] | select(.name == "$BRANCH_NAME")')

# Check if the output is empty
if [ -z "$output" ]; then
  # The output is empty, so clone the environment
  qovery environment clone \
    --organization "x" \
    --project "x" \
    --environment "entity-store" \
    --new-environment-name "$BRANCH_NAME"
else
  echo "Environment 'Toto' found, no need to clone."
fi

Then you make sure you don’t skip any potential errors while cloning.

qovery environment list --json

wont work will it as it needs you to run in the config cli context first? just tried locally, and you can add org, project! giving it a whirl

ty

1 Like

thats a lot cleaner thank you!

1 Like