Skip to content

Commit 6f9f33b

Browse files
author
Anton
authored
CLOUDP-82782: flexible push-files action (signed commits) (#162)
1 parent 157dace commit 6f9f33b

File tree

4 files changed

+39
-73
lines changed

4 files changed

+39
-73
lines changed

.github/actions/push-files/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#TODO change to alpine
21
FROM alpine/git:latest
32

43
# Install GitHub CLI
54
RUN apk update && \
6-
apk add --no-cache libc6-compat
5+
apk add --no-cache libc6-compat bash
76
RUN mkdir ghcli && cd ghcli && \
87
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 && \
98
tar --strip-components=1 -xf ghcli.tar.gz -C /usr/local

.github/actions/push-files/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ inputs:
44
GITHUB_TOKEN:
55
description: "Action token"
66
required: true
7-
FILE_TO_COMMIT:
8-
description: "Target file which will be committed"
7+
PATH_TO_COMMIT:
8+
description: "Target file or directory which will be committed"
99
required: true
1010
DESTINATION_BRANCH:
1111
description: "Target branch"

.github/actions/push-files/entrypoint.sh

100644100755
Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

3-
#set -eou pipefail
3+
set -eou pipefail
44

5-
#commit file to the destination branch
5+
commit_single_file() {
6+
# Commit to the branch
7+
file="$1"
8+
sha=$(git rev-parse "$DESTINATION_BRANCH:$file") || true
9+
content=$(base64 "$file")
10+
message="Pushing $file using GitHub API"
611

7-
MESSAGE="generated $FILE_TO_COMMIT"
8-
SHA=$(git rev-parse "$DESTINATION_BRANCH:$FILE_TO_COMMIT")
9-
CONTENT=$(base64 "$FILE_TO_COMMIT")
10-
echo "$DESTINATION_BRANCH:$FILE_TO_COMMIT:$SHA"
12+
echo "$DESTINATION_BRANCH:$file:$sha"
13+
if [ "$sha" = "$DESTINATION_BRANCH:$file" ]; then
14+
echo "File does not exist"
15+
gh api --method PUT "/repos/:owner/:repo/contents/$file" \
16+
--field message="$message" \
17+
--field content="$content" \
18+
--field encoding="base64" \
19+
--field branch="$DESTINATION_BRANCH"
20+
else
21+
echo "File exists"
22+
gh api --method PUT "/repos/:owner/:repo/contents/$file" \
23+
--field message="$message" \
24+
--field content="$content" \
25+
--field encoding="base64" \
26+
--field branch="$DESTINATION_BRANCH" \
27+
--field sha="$sha"
28+
fi
29+
}
30+
31+
# simple 'for loop' does not work correctly, see https://github.com/koalaman/shellcheck/wiki/SC2044#correct-code
32+
while IFS= read -r -d '' file
33+
do
34+
commit_single_file "$file"
35+
done < <(find "${PATH_TO_COMMIT}" -type f -print0)
1136

12-
# Commit to the branch
13-
if [ "$SHA" = "$DESTINATION_BRANCH:$FILE_TO_COMMIT" ]; then
14-
echo "File does not exist"
15-
gh api --method PUT "/repos/:owner/:repo/contents/$FILE_TO_COMMIT" \
16-
--field message="$MESSAGE" \
17-
--field content="$CONTENT" \
18-
--field encoding="base64" \
19-
--field branch="$DESTINATION_BRANCH"
20-
else
21-
echo "File exists"
22-
gh api --method PUT "/repos/:owner/:repo/contents/$FILE_TO_COMMIT" \
23-
--field message="$MESSAGE" \
24-
--field content="$CONTENT" \
25-
--field encoding="base64" \
26-
--field branch="$DESTINATION_BRANCH" \
27-
--field sha="$SHA"
28-
fi

.github/workflows/release-branch.yml

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
description: "Release version:"
1111
required: true
1212

13+
1314
jobs:
1415
create-release-branch:
1516
name: Create Release
@@ -25,7 +26,7 @@ jobs:
2526
with:
2627
fetch-depth: 0 #required for tags
2728

28-
- name: Create all-in-one installation script
29+
- name: Create deploy configurations
2930
uses: ./.github/actions/gen-install-scripts
3031
with:
3132
IMAGE_URL: ${{ env.DOCKER_RELEASE_REPO }}:${{ env.VERSION }}
@@ -36,53 +37,11 @@ jobs:
3637
git checkout -b "release/${VERSION}"
3738
git push origin "release/${VERSION}"
3839
39-
- name: Commit all-in-one
40-
uses: ./.github/actions/push-files
41-
env:
42-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43-
FILE_TO_COMMIT: "deploy/all-in-one.yaml"
44-
DESTINATION_BRANCH: "release/${{ env.VERSION }}"
45-
46-
- name: Commit crd project
47-
uses: ./.github/actions/push-files
48-
env:
49-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50-
FILE_TO_COMMIT: "deploy/crds/atlas.mongodb.com_atlasprojects.yaml"
51-
DESTINATION_BRANCH: "release/${{ env.VERSION }}"
52-
53-
- name: Commit crd cluster
54-
uses: ./.github/actions/push-files
55-
env:
56-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57-
FILE_TO_COMMIT: "deploy/crds/atlas.mongodb.com_atlasclusters.yaml"
58-
DESTINATION_BRANCH: "release/${{ env.VERSION }}"
59-
60-
- name: Commit namespaced crds
61-
uses: ./.github/actions/push-files
62-
env:
63-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64-
FILE_TO_COMMIT: "deploy/namespaced/crds.yaml"
65-
DESTINATION_BRANCH: "release/${{ env.VERSION }}"
66-
67-
- name: Commit namespaced config
68-
uses: ./.github/actions/push-files
69-
env:
70-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71-
FILE_TO_COMMIT: "deploy/namespaced/namespaced-config.yaml"
72-
DESTINATION_BRANCH: "release/${{ env.VERSION }}"
73-
74-
- name: Commit clusterwide crds
75-
uses: ./.github/actions/push-files
76-
env:
77-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78-
FILE_TO_COMMIT: "deploy/clusterwide/crds.yaml"
79-
DESTINATION_BRANCH: "release/${{ env.VERSION }}"
80-
81-
- name: Commit clusterwide config
40+
- name: Commit and push deploy directory
8241
uses: ./.github/actions/push-files
8342
env:
8443
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85-
FILE_TO_COMMIT: "deploy/clusterwide/clusterwide-config.yaml"
44+
PATH_TO_COMMIT: "deploy"
8645
DESTINATION_BRANCH: "release/${{ env.VERSION }}"
8746

8847
- name: Create PR

0 commit comments

Comments
 (0)