diff --git a/.github/workflows/m2k-func.yaml b/.github/workflows/m2k-func.yaml index 5f4c8d76..e34bb14f 100644 --- a/.github/workflows/m2k-func.yaml +++ b/.github/workflows/m2k-func.yaml @@ -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: @@ -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 @@ -77,8 +84,9 @@ jobs: - name: Send PRs to config repo if: ${{ ! inputs.it_mode }} + env: + GH_TOKEN: ${{ secrets.HELM_REPO_TOKEN }} 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 }}" @@ -86,24 +94,14 @@ jobs: 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 || 'parodos@redhat.com' }}" - 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 || 'parodos@redhat.com' }} \ ${{ github.event.head_commit.author.name || github.triggering_actor }} \ - $WORKDIR \ + ${{ env.WORKDIR }} \ ${{ env.GH_TOKEN }} \ - $WF_CONFIG_REPO + $WF_CONFIG_REPO \ + ${{ github.sha }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 96d0b05a..e1333a6d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 }} diff --git a/scripts/create_automated_m2k_kfunc_pr.sh b/scripts/create_automated_m2k_kfunc_pr.sh index 784cf3fe..4d964030 100644 --- a/scripts/create_automated_m2k_kfunc_pr.sh +++ b/scripts/create_automated_m2k_kfunc_pr.sh @@ -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" diff --git a/scripts/create_or_update_automated_pr.sh b/scripts/create_or_update_automated_pr.sh index 1352f530..6d8115a8 100644 --- a/scripts/create_or_update_automated_pr.sh +++ b/scripts/create_or_update_automated_pr.sh @@ -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 @@ -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 @@ -42,7 +44,7 @@ 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" @@ -50,14 +52,14 @@ for pr in $prs; do # 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" @@ -72,4 +74,5 @@ sh "${CREATE_PR_SCRIPT}" "${USER_EMAIL}" \ "${WORKFLOW_ID}" \ "${PR_OR_COMMIT_URL}" \ "${GH_TOKEN}" \ - "${WF_CONFIG_REPO}" + "${REPO}" \ + "${GITHUB_SHA}" \ No newline at end of file