Skip to content

Commit

Permalink
change triggers workflow when changes are deteched in operator compon…
Browse files Browse the repository at this point in the history
…ent charts template
  • Loading branch information
olamilekan000 committed Jan 21, 2025
1 parent 3dd08df commit 624a6cf
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/move_crd_values_to_operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Move Operator CRD Manifest File To Operator

on:
push:
branches:
- master

jobs:
check-specific-file:
runs-on: ubuntu-latest
outputs:
CHANGED: ${{ steps.check_changes.outputs.CHANGED }}

steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get Source Branch Name
id: get_source_branch
run: |
MERGE_COMMIT=$(git --no-pager log -1 --merges --pretty=%H)
SOURCE_BRANCH=$(git show -s --pretty=%B $MERGE_COMMIT | grep -oP '(?<=from )\S+' | sed 's/^[^/]*\///')
echo "SOURCE_BRANCH=${SOURCE_BRANCH}" >> $GITHUB_ENV
if [[ "$SOURCE_BRANCH" == *operator-release* ]]; then
echo "Branch is a release 'release', exiting pipeline."
exit 0
fi
- name: Check for Changes in components/tyk-operator/templates/all.yaml
id: check_changes
run: |
echo "Checking for changes between in ${{ env.SOURCE_BRANCH }} branch"
git fetch origin ${{ env.SOURCE_BRANCH }}
if git --no-pager log -n 1 origin/${{ env.SOURCE_BRANCH }} --name-only --pretty=format: | grep -q "components/tyk-operator/templates/all.yaml"; then
echo "CHANGED=true" >> $GITHUB_OUTPUT
else
echo "CHANGED=false" >> $GITHUB_OUTPUT
fi
- name: Copy Manifest file into a temporary directory
if: ${{ steps.check_changes.outputs.CHANGED == 'true' }}
run: |
mkdir -p /tmp/helm
mkdir -p /tmp/charts
cp -r "${GITHUB_WORKSPACE}/components/tyk-operator/templates/all.yaml" /tmp/helm/charts-all.yaml
cp -r "${GITHUB_WORKSPACE}/components/tyk-operator/Chart.yaml" /tmp/charts/
cp -r "${GITHUB_WORKSPACE}/components/tyk-operator/values.yaml" /tmp/charts/
- name: Upload Manifest file
if: ${{ steps.check_changes.outputs.CHANGED == 'true' }}
uses: actions/upload-artifact@v4
with:
name: helm
path: /tmp/helm

- name: Upload Manifest file
if: ${{ steps.check_changes.outputs.CHANGED == 'true' }}
uses: actions/upload-artifact@v4
with:
name: charts
path: /tmp/charts
process-changes:
needs: check-specific-file
runs-on: ubuntu-latest
if: ${{ needs.check-specific-file.outputs.CHANGED == 'true' }}

steps:
- name: Checkout other repository
uses: actions/checkout@v4
with:
repository: TykTechnologies/tyk-operator-internal
token: ${{ secrets.PAT }}

- name: Create and checkout new branch
run: |
SHORT_UID=$(uuidgen | cut -c1-8)
echo "SHORT_UID=$SHORT_UID" >> $GITHUB_ENV
git checkout -b file-changed-${{ env.TAG }}-$SHORT_UID
- name: Download Manifest file directly into the templates directory
uses: actions/download-artifact@v4
with:
name: helm
path: /helm/templates/

- name: Download Chart.yaml and Values.yaml files
uses: actions/download-artifact@v4
with:
name: charts
path: /helm/

- name: Commit and push changes
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add .
git commit -m "add new change to file version ${{ env.TAG }}-${{ env.SHORT_UID }}"
git push origin file-changed-${{ env.TAG }}-${{ env.SHORT_UID }}
- name: Create a pull request
run: |
gh pr create --base main --head file-changed-${{ env.TAG }}-${{ env.SHORT_UID }} \
--title "Update Tyk Operator Templates for version file-changed-${{ env.TAG }}-${{ env.SHORT_UID }}" \
--body "Changes include Templates updates from Tyk Operator for file-changed-${{ env.TAG }}-${{ env.SHORT_UID }}."
env:
GITHUB_TOKEN: ${{ secrets.PAT }}

0 comments on commit 624a6cf

Please sign in to comment.