Skip to content

Commit

Permalink
Fixing M2K Kfunc
Browse files Browse the repository at this point in the history
Signed-off-by: gabriel-farache <[email protected]>
  • Loading branch information
gabriel-farache committed Oct 11, 2024
1 parent 48759c9 commit 5f03378
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
28 changes: 12 additions & 16 deletions .github/workflows/m2k-func.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
MVN_OPTS: ""
WF_CONFIG_REPO: parodos-dev/serverless-workflows-config
REGISTRY_REPO: orchestrator
GH_TOKEN: ${{ secrets.HELM_REPO_TOKEN }}
GH_TOKEN: ${{ secrets.HELM_REPO_TOKEN }}

jobs:
build-and-push-m2k-func:
Expand All @@ -25,6 +25,13 @@ jobs:
java-version: '17'
distribution: 'temurin'

- name: Log in to Red Hat Registry
uses: redhat-actions/podman-login@v1
with:
registry: registry.redhat.io
username: ${{ secrets.REGISTRY_REDHAT_IO_USER }}
password: ${{ secrets.REGISTRY_REDHAT_IO_PASSWORD }}

- name: Buildah Action
id: build-image
uses: redhat-actions/buildah-build@v2
Expand Down Expand Up @@ -78,32 +85,21 @@ jobs:
- name: Send PRs to config repo
if: ${{ ! inputs.it_mode }}
run: |
WORKDIR=${{ runner.temp }}/serverless-workflows
# determine pr or commit url
if [ ${{ fromJSON(steps.get_pr_data.outputs.result)}} != "" ]; then
PR_OR_COMMIT_URL="${{ fromJSON(steps.get_pr_data.outputs.result).html_url }}"
else
PR_OR_COMMIT_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
fi
git config --global user.email "${{ github.event.head_commit.author.email || '[email protected]' }}"
git config --global user.name ${{ github.event.head_commit.author.name || github.triggering_actor }}
gh repo clone $WF_CONFIG_REPO config-repo
cd config-repo
git switch -c m2k-kfunc-autopr-$RANDOM
./hack/bump_chart_version.sh move2kube --bump-tag-version
yq --inplace '.kfunction.image="quay.io/orchestrator/serverless-workflow-m2k-kfunc:${{ github.sha }}"' charts/move2kube/values.yaml
cd ..
echo "Running create_or_update_automated_pr script"
sh scripts/create_or_update_automated_pr.sh $WF_CONFIG_REPO \
${{ inputs.workflow_id }} \
${PR_OR_COMMIT_URL} \
config-repo/charts/move2kube/values.yaml \
"yq --inplace '.kfunction.image=\"quay.io/orchestrator/serverless-workflow-m2k-kfunc:'\"${GITHUB_SHA}\"'\"' charts/move2kube/values.yaml" \
scripts/create_automated_m2k_kfunc_pr.sh \
${{ github.event.head_commit.author.email || '[email protected]' }} \
${{ github.event.head_commit.author.name || github.triggering_actor }} \
$WORKDIR \
${{ env.WORKDIR }} \
${{ env.GH_TOKEN }} \
$WF_CONFIG_REPO
$WF_CONFIG_REPO \
${{ github.sha }}
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,6 @@ jobs:
${{ github.event.head_commit.author.name || github.triggering_actor }} \
$WORKDIR \
${{ env.GH_TOKEN }} \
$WF_CONFIG_REPO
$WF_CONFIG_REPO \
${{ github.sha }}
6 changes: 6 additions & 0 deletions scripts/create_automated_m2k_kfunc_pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ WORKFLOW_ID=$4
PR_OR_COMMIT_URL=$5
GH_TOKEN=$6
WF_CONFIG_REPO=$7
GITHUB_SHA=$8

TIMESTAMP=$(date +%s)
git config --global user.email "${USER_EMAIL}"
git config --global user.name "${USER_NAME}"
gh repo clone "${WF_CONFIG_REPO}" config-repo
cd config-repo || exit
git switch -c "${WORKFLOW_ID}"-autopr-"${TIMESTAMP}"

./hack/bump_chart_version.sh "${WORKFLOW_ID}" --bump-tag-version
mkdir -p charts/"${WORKFLOW_ID}"/templates
cp "${WORKDIR}"/"${WORKFLOW_ID}"/manifests/* charts/"${WORKFLOW_ID}"/templates
yq --inplace '.kfunction.image="quay.io/orchestrator/serverless-workflow-m2k-kfunc:'"${GITHUB_SHA}"'"' charts/move2kube/values.yaml
git add -A

git commit -m "(m2k-kfunc) Automated PR"
Expand Down
17 changes: 10 additions & 7 deletions scripts/create_or_update_automated_pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ USER_EMAIL=$6
USER_NAME=$7
WORKDIR=$8
GH_TOKEN=$9
WF_CONFIG_REPO=${10}
GITHUB_SHA=${10}

# Get all open PRs for the repository
prs=$(gh pr list --repo "${REPO}" --json number --jq '.[].number')
echo "gh pr list --repo "${REPO}" --json number --jq '.[].number'"
prs=$(gh pr list --repo "${REPO}" --json number --jq '.[].number') || exit
echo "${prs}"
STOP=false
# Loop through each PR and check for the version in Chart.yaml
for pr in $prs; do
Expand All @@ -25,7 +27,7 @@ for pr in $prs; do
fi

# Fetch the list of changed files for the PR
files=$(gh pr diff "$pr" --name-only --repo "${REPO}")
files=$(gh pr diff "$pr" --name-only --repo "${REPO}") || exit

# Check if Chart.yaml is in the list of changed files
if echo "$files" | grep -q "charts/${WORKFLOW_ID}/Chart.yaml"; then
Expand All @@ -42,22 +44,22 @@ for pr in $prs; do
# Get the PR details (branch)
pr_branch=$(gh pr view "$pr" --repo "$REPO" --json headRefName --jq '.headRefName')

gh repo clone "${WF_CONFIG_REPO}" config-repo
gh repo clone "${REPO}" config-repo
cd config-repo || exit
# Checkout the PR branch
git checkout "$pr_branch"

# Create the new file
cp "${WORKDIR}"/"${WORKFLOW_ID}"/manifests/* charts/"${WORKFLOW_ID}"/templates || exit 1
if [ "${INPUT_VALUES_FILEPATH}" != "" ]; then
cp "${INPUT_VALUES_FILEPATH}" "charts/${WORKFLOW_ID}/values.yaml" || exit 1
eval "${INPUT_VALUES_FILEPATH}" || exit 1
fi
git add -A

git commit -m "(${WORKFLOW_ID}) Automated PR"
echo "Automated PR from $PR_OR_COMMIT_URL" | git commit --amend --file=-

git remote set-url origin https://"${GH_TOKEN}"@github.com/"${WF_CONFIG_REPO}" || exit 1
git remote set-url origin https://"${GH_TOKEN}"@github.com/"${REPO}" || exit 1
git push origin HEAD || exit 1

echo "Changes pushed to PR #$pr on branch $pr_branch"
Expand All @@ -72,4 +74,5 @@ sh "${CREATE_PR_SCRIPT}" "${USER_EMAIL}" \
"${WORKFLOW_ID}" \
"${PR_OR_COMMIT_URL}" \
"${GH_TOKEN}" \
"${WF_CONFIG_REPO}"
"${REPO}" \
"${GITHUB_SHA}"

0 comments on commit 5f03378

Please sign in to comment.