Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️ Bump yq version #41

Merged
merged 5 commits into from
Jul 12, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,17 @@ runs:
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Checkout GitOps Repository
if: inputs.gitopsenabled == 'true'
uses: actions/checkout@v3
with:
repository: ${{ inputs.gitopsorganization }}/${{ inputs.gitopsrepository }}
token: ${{ inputs.gitopstoken }}
path: .github/${{ inputs.gitopsrepository }}

- name: Update Docker Image in Repository
if: inputs.gitopsenabled == 'true'
working-directory: .github/${{ inputs.gitopsrepository }}
shell: bash
run: |
commit_changes () {
Expand All @@ -152,53 +161,50 @@ runs:
fi
}

# download and install yq
sudo wget -O /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/3.4.1/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
Comment on lines -155 to -157
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


# configure git user
git config --global user.email "${{ inputs.gitopsemail }}" && git config --global user.name "${{ inputs.gitopsuser }}"

git clone https://${{ inputs.gitopsuser }}:${{ inputs.gitopstoken }}@github.com/${{ inputs.gitopsorganization }}/${{ inputs.gitopsrepository }}.git .github/${{ inputs.gitopsrepository }}
cd .github/${{ inputs.gitopsrepository }}
echo "Repository ${{ inputs.gitopsorganization }}/${{ inputs.gitopsrepository }} was cloned successfully "
Comment on lines -161 to -163
Copy link
Contributor Author

@flaxel flaxel Jul 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use explicit checkout action


if [[ ( $GITHUB_REF == refs/heads/master || $GITHUB_REF == refs/heads/main ) && -n "${{ inputs.gitopsstage }}" ]]; then
echo "Run update for STAGE"
while IFS= read -r line; do
array=($line)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split input by blank

echo "Check if path $line exists and get old current version"
yq r -e $line
yq -e .${array[1]} ${array[0]}
echo "Run update $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}"
yq w -i $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}
yq -i .${array[1]}=\"${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}\" ${array[0]}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

migrated the calls from version 3 to 4

done <<< "${{ inputs.gitopsstage }}"
commit_changes

elif [[ $GITHUB_REF == refs/heads/dev && -n "${{ inputs.gitopsdev }}" ]]; then
echo "Run update for DEV"
while IFS= read -r line; do
array=($line)
echo "Check if path $line exists and get old current version"
yq r -e $line
yq -e .${array[1]} ${array[0]}
echo "Run update $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}"
yq w -i $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}
yq -i .${array[1]}=\"${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}\" ${array[0]}
done <<< "${{ inputs.gitopsdev }}"
commit_changes

elif [[ $GITHUB_REF == refs/tags/* && -n "${{ inputs.gitopsprod }}" ]]; then
echo "Run update for PROD"
while IFS= read -r line; do
array=($line)
echo "Check if path $line exists and get old current version"
yq r -e $line
yq -e .${array[1]} ${array[0]}
echo "Run update $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}"
yq w -i $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}
yq -i .${array[1]}=\"${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}\" ${array[0]}
done <<< "${{ inputs.gitopsprod }}"
commit_changes

elif [[ -n "${{ inputs.gitopsdev }}" ]]; then
echo "Simulate update for DEV"
while IFS= read -r line; do
array=($line)
echo "Check if path $line exists and get old current version"
yq r -e $line
yq -e .${array[1]} ${array[0]}
echo "Run update $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}"
yq w -i $line ${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}
yq -i .${array[1]}=\"${{ inputs.dockerregistry }}/${{ inputs.dockerimage }}:${{ steps.preparation.outputs.tag }}\" ${array[0]}
done <<< "${{ inputs.gitopsdev }}"
commit_changes
fi