Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github actions only on first push

I'm working on a github action that creates an app on ArgoCD. The problem is that I want to execute it only once, the first time that it gets push with the k8s yamls.
Is there any way to restrict the github action to the first push on the repo?
I have been looking to the github triggers, but I was not able to find any relation.

This is a sample of the action:

on: push
name: deploy-argo-app
jobs:
  deploy-argo-app:
    name: Deploy new app on ArgoCD
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: Install Argo Cli
      run: |
          VERSION=$(curl --silent "https://api.github.com/repos/argoproj/argo-cd/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
          sudo curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/download/$VERSION/argocd-linux-amd64
          sudo chmod +x /usr/local/bin/argocd
    - name: Create app
      run: | 
          argocd app create guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook --dest-server https://kubernetes.default.svc --dest-namespace default
like image 588
radicaled Avatar asked May 01 '26 09:05

radicaled


1 Answers

I have been looking for something similar, but I needed to know the first push on any given branch.

First, you can see everything available to you on your Github context by running this worfklow:

      - name: Dump GitHub context
        id: github_context_step
        run: echo '${{ toJSON(github) }}'

I was able to see that on the first push to any branch the

github.event.before = 0000000000000000000000000000000000000000

and

github.event.created = true

whereas for any subsequent push to that same branch the github.event.before will give a numerical reference to the previous commit, and the github.event.created will be false.

Slightly related, but maybe still useful for people who find themselves on the same hunt I was on!

like image 177
McKynlee Westman Avatar answered May 06 '26 05:05

McKynlee Westman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!