From b2b0b124debab90760828cc475521bda3419e28d Mon Sep 17 00:00:00 2001 From: antonlisovenko Date: Mon, 8 Mar 2021 17:56:12 +0000 Subject: [PATCH 1/6] CLOUDP-82782: flexible push --- .github/actions/push-files/entrypoint.sh | 56 ++++++++++++++---------- .github/workflows/release-branch.yml | 49 ++------------------- 2 files changed, 36 insertions(+), 69 deletions(-) mode change 100644 => 100755 .github/actions/push-files/entrypoint.sh diff --git a/.github/actions/push-files/entrypoint.sh b/.github/actions/push-files/entrypoint.sh old mode 100644 new mode 100755 index bba1165dd2..6609cbf596 --- a/.github/actions/push-files/entrypoint.sh +++ b/.github/actions/push-files/entrypoint.sh @@ -1,28 +1,36 @@ -#!/bin/sh +#!/bin/bash -#set -eou pipefail +set -xeou pipefail -#commit file to the destination branch +commit_single_file() { + # Commit to the branch + file="$1" + sha=$(git rev-parse "$DESTINATION_BRANCH:$file") || true + content=$(base64 "$file") + message="Pushing $file using GitHub API" -MESSAGE="generated $FILE_TO_COMMIT" -SHA=$(git rev-parse "$DESTINATION_BRANCH:$FILE_TO_COMMIT") -CONTENT=$(base64 "$FILE_TO_COMMIT") -echo "$DESTINATION_BRANCH:$FILE_TO_COMMIT:$SHA" + echo "$DESTINATION_BRANCH:$file:$sha" + if [ "$sha" = "$DESTINATION_BRANCH:$file" ]; then + echo "File does not exist" + gh api --method PUT "/repos/:owner/:repo/contents/$file" \ + --field message="$message" \ + --field content="$content" \ + --field encoding="base64" \ + --field branch="$DESTINATION_BRANCH" + else + echo "File exists" + gh api --method PUT "/repos/:owner/:repo/contents/$file" \ + --field message="$message" \ + --field content="$content" \ + --field encoding="base64" \ + --field branch="$DESTINATION_BRANCH" \ + --field sha="$sha" + fi +} + +# simple 'for loop' does not work correctly, see https://github.com/koalaman/shellcheck/wiki/SC2044#correct-code +while IFS= read -r -d '' file +do + commit_single_file "$file" +done < <(find "${FILE_TO_COMMIT}" -type f -print0) -# Commit to the branch -if [ "$SHA" = "$DESTINATION_BRANCH:$FILE_TO_COMMIT" ]; then - echo "File does not exist" - gh api --method PUT "/repos/:owner/:repo/contents/$FILE_TO_COMMIT" \ - --field message="$MESSAGE" \ - --field content="$CONTENT" \ - --field encoding="base64" \ - --field branch="$DESTINATION_BRANCH" -else - echo "File exists" - gh api --method PUT "/repos/:owner/:repo/contents/$FILE_TO_COMMIT" \ - --field message="$MESSAGE" \ - --field content="$CONTENT" \ - --field encoding="base64" \ - --field branch="$DESTINATION_BRANCH" \ - --field sha="$SHA" -fi diff --git a/.github/workflows/release-branch.yml b/.github/workflows/release-branch.yml index c4bf124971..5fb0587cd4 100644 --- a/.github/workflows/release-branch.yml +++ b/.github/workflows/release-branch.yml @@ -10,6 +10,7 @@ on: description: "Release version:" required: true + jobs: create-release-branch: name: Create Release @@ -25,7 +26,7 @@ jobs: with: fetch-depth: 0 #required for tags - - name: Create all-in-one installation script + - name: Create deploy configurations uses: ./.github/actions/gen-install-scripts with: IMAGE_URL: ${{ env.DOCKER_RELEASE_REPO }}:${{ env.VERSION }} @@ -36,53 +37,11 @@ jobs: git checkout -b "release/${VERSION}" git push origin "release/${VERSION}" - - name: Commit all-in-one - uses: ./.github/actions/push-files - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - FILE_TO_COMMIT: "deploy/all-in-one.yaml" - DESTINATION_BRANCH: "release/${{ env.VERSION }}" - - - name: Commit crd project - uses: ./.github/actions/push-files - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - FILE_TO_COMMIT: "deploy/crds/atlas.mongodb.com_atlasprojects.yaml" - DESTINATION_BRANCH: "release/${{ env.VERSION }}" - - - name: Commit crd cluster - uses: ./.github/actions/push-files - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - FILE_TO_COMMIT: "deploy/crds/atlas.mongodb.com_atlasclusters.yaml" - DESTINATION_BRANCH: "release/${{ env.VERSION }}" - - - name: Commit namespaced crds - uses: ./.github/actions/push-files - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - FILE_TO_COMMIT: "deploy/namespaced/crds.yaml" - DESTINATION_BRANCH: "release/${{ env.VERSION }}" - - - name: Commit namespaced config - uses: ./.github/actions/push-files - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - FILE_TO_COMMIT: "deploy/namespaced/namespaced-config.yaml" - DESTINATION_BRANCH: "release/${{ env.VERSION }}" - - - name: Commit clusterwide crds - uses: ./.github/actions/push-files - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - FILE_TO_COMMIT: "deploy/clusterwide/crds.yaml" - DESTINATION_BRANCH: "release/${{ env.VERSION }}" - - - name: Commit clusterwide config + - name: Commit deploy directory uses: ./.github/actions/push-files env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - FILE_TO_COMMIT: "deploy/clusterwide/clusterwide-config.yaml" + FILE_TO_COMMIT: "deploy" DESTINATION_BRANCH: "release/${{ env.VERSION }}" - name: Create PR From 011db8d9828fc84e785d7fcbd3c17b615cce4a38 Mon Sep 17 00:00:00 2001 From: antonlisovenko Date: Mon, 8 Mar 2021 18:03:53 +0000 Subject: [PATCH 2/6] wip --- .github/actions/push-files/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/push-files/Dockerfile b/.github/actions/push-files/Dockerfile index df77188e5b..66df9fa0fa 100644 --- a/.github/actions/push-files/Dockerfile +++ b/.github/actions/push-files/Dockerfile @@ -3,7 +3,7 @@ FROM alpine/git:latest # Install GitHub CLI RUN apk update && \ - apk add --no-cache libc6-compat + apk add --no-cache libc6-compat bash RUN mkdir ghcli && cd ghcli && \ wget https://github.com/cli/cli/releases/download/v1.5.0/gh_1.5.0_linux_386.tar.gz -O ghcli.tar.gz --no-check-certificate && \ tar --strip-components=1 -xf ghcli.tar.gz -C /usr/local From 060e4c8a5174ea782940397b8f202694e95dc5f2 Mon Sep 17 00:00:00 2001 From: antonlisovenko Date: Mon, 8 Mar 2021 18:09:33 +0000 Subject: [PATCH 3/6] wip --- .github/actions/push-files/Dockerfile | 1 - .github/actions/push-files/entrypoint.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/actions/push-files/Dockerfile b/.github/actions/push-files/Dockerfile index 66df9fa0fa..c2f5b2d1c6 100644 --- a/.github/actions/push-files/Dockerfile +++ b/.github/actions/push-files/Dockerfile @@ -1,4 +1,3 @@ -#TODO change to alpine FROM alpine/git:latest # Install GitHub CLI diff --git a/.github/actions/push-files/entrypoint.sh b/.github/actions/push-files/entrypoint.sh index 6609cbf596..511d335269 100755 --- a/.github/actions/push-files/entrypoint.sh +++ b/.github/actions/push-files/entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -xeou pipefail +set -eou pipefail commit_single_file() { # Commit to the branch From 8f65e31b7b6cf95b7ae029ddc4ba348a74b758a4 Mon Sep 17 00:00:00 2001 From: antonlisovenko Date: Mon, 8 Mar 2021 18:10:40 +0000 Subject: [PATCH 4/6] wip --- .github/workflows/release-branch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-branch.yml b/.github/workflows/release-branch.yml index 5fb0587cd4..c11738a0b4 100644 --- a/.github/workflows/release-branch.yml +++ b/.github/workflows/release-branch.yml @@ -37,7 +37,7 @@ jobs: git checkout -b "release/${VERSION}" git push origin "release/${VERSION}" - - name: Commit deploy directory + - name: Commit and push deploy directory uses: ./.github/actions/push-files env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 4e53ea19c221d7fe867c98cd9f2c99cf7002e923 Mon Sep 17 00:00:00 2001 From: antonlisovenko Date: Tue, 9 Mar 2021 10:53:01 +0000 Subject: [PATCH 5/6] renamed to `PATH_TO_COMMIT` --- .github/actions/push-files/action.yml | 2 +- .github/actions/push-files/entrypoint.sh | 2 +- .github/workflows/release-branch.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/push-files/action.yml b/.github/actions/push-files/action.yml index ae1191c6dc..ce0ad54f8d 100644 --- a/.github/actions/push-files/action.yml +++ b/.github/actions/push-files/action.yml @@ -4,7 +4,7 @@ inputs: GITHUB_TOKEN: description: "Action token" required: true - FILE_TO_COMMIT: + PATH_TO_COMMIT: description: "Target file which will be committed" required: true DESTINATION_BRANCH: diff --git a/.github/actions/push-files/entrypoint.sh b/.github/actions/push-files/entrypoint.sh index 511d335269..ebed059dfd 100755 --- a/.github/actions/push-files/entrypoint.sh +++ b/.github/actions/push-files/entrypoint.sh @@ -32,5 +32,5 @@ commit_single_file() { while IFS= read -r -d '' file do commit_single_file "$file" -done < <(find "${FILE_TO_COMMIT}" -type f -print0) +done < <(find "${PATH_TO_COMMIT}" -type f -print0) diff --git a/.github/workflows/release-branch.yml b/.github/workflows/release-branch.yml index c11738a0b4..be3b0da67d 100644 --- a/.github/workflows/release-branch.yml +++ b/.github/workflows/release-branch.yml @@ -41,7 +41,7 @@ jobs: uses: ./.github/actions/push-files env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - FILE_TO_COMMIT: "deploy" + PATH_TO_COMMIT: "deploy" DESTINATION_BRANCH: "release/${{ env.VERSION }}" - name: Create PR From ffc2f7c586c8eff48a7b2ba82a2c7fd18ddbcaec Mon Sep 17 00:00:00 2001 From: antonlisovenko Date: Tue, 9 Mar 2021 14:17:04 +0000 Subject: [PATCH 6/6] pr comment --- .github/actions/push-files/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/push-files/action.yml b/.github/actions/push-files/action.yml index ce0ad54f8d..04800149f7 100644 --- a/.github/actions/push-files/action.yml +++ b/.github/actions/push-files/action.yml @@ -5,7 +5,7 @@ inputs: description: "Action token" required: true PATH_TO_COMMIT: - description: "Target file which will be committed" + description: "Target file or directory which will be committed" required: true DESTINATION_BRANCH: description: "Target branch"