diff --git a/.github/workflows/chainloop_contract_sync.yml b/.github/workflows/chainloop_contract_sync.yml index 4779bd5..9424d02 100644 --- a/.github/workflows/chainloop_contract_sync.yml +++ b/.github/workflows/chainloop_contract_sync.yml @@ -28,15 +28,23 @@ jobs: with: fetch-depth: 0 - - name: Update contracts ${{ inputs.contract_root_folder }} on Chainloop + - name: Sync contracts ${{ inputs.contract_root_folder }} on Chainloop run: | - for file in $(ls ${{ inputs.contract_root_folder }}); do - if [[ $file = *.yml || $file = *.yaml ]]; then - contract_name=$(basename $file | cut -d'.' -f1) - echo "Updating contract $contract_name with ${{ inputs.contract_root_folder }}/$file" - chainloop wf contract update --name $contract_name --contract ${{ inputs.contract_root_folder }}/$file - fi - done + for file in $(ls ${{ inputs.contract_root_folder }}); do + if [[ $file = *.yml || $file = *.yaml ]]; then + contract_name=$(basename $file | cut -d'.' -f1) + contract_file="${{ inputs.contract_root_folder }}/$file" + + echo "Checking if contract $contract_name exists..." + if chainloop wf contract describe --name $contract_name >/dev/null 2>&1; then + echo "Contract $contract_name exists, updating..." + chainloop wf contract update --name $contract_name --contract $contract_file + else + echo "Contract $contract_name does not exist, creating..." + chainloop wf contract create --name $contract_name --contract $contract_file + fi + fi + done env: CHAINLOOP_VERSION: ${{ inputs.chainloop_version }}