Skip to content

Commit 012ab31

Browse files
committed
Use pac-gitauth secret for push
1 parent b6757d7 commit 012ab31

File tree

3 files changed

+18
-62
lines changed

3 files changed

+18
-62
lines changed

.tekton/pipeline/update-repository.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ spec:
1010
- name: repo_url
1111
- name: source_branch
1212
workspaces:
13+
- name: basic-auth
1314
- name: workdir
1415
tasks:
1516
- name: update-binaries
@@ -37,6 +38,8 @@ spec:
3738
- --workspace_dir
3839
- "."
3940
workspaces:
41+
- name: basic-auth
42+
workspace: basic-auth
4043
- name: workdir
4144
workspace: workdir
4245
- name: update-images
@@ -66,5 +69,7 @@ spec:
6669
- --workspace_dir
6770
- "."
6871
workspaces:
72+
- name: basic-auth
73+
workspace: basic-auth
6974
- name: workdir
7075
workspace: workdir

.tekton/tasks/update-repository.yaml

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ spec:
9898
value: $(params.TARGET_GH_NAME)
9999
- name: TARGET_GH_OWNER
100100
value: $(params.TARGET_GH_OWNER)
101+
- name: WORKSPACE_BASIC_AUTH_DIRECTORY_PATH
102+
value: $(workspaces.basic-auth.path)
101103
args: ["$(params.SCRIPT_ARGS[*])"]
102104
script: |
103105
#!/bin/bash
@@ -116,77 +118,22 @@ spec:
116118
git config --global safe.directory "${PWD}"
117119
git config --local user.email "$GIT_EMAIL"
118120
git config --local user.name "$GIT_USER"
121+
git remote set-url origin "$(cat "$WORKSPACE_BASIC_AUTH_DIRECTORY_PATH/.git-credentials")"
119122
120123
# Create branch
121124
git branch --copy --force "$COMMIT_BRANCH"
122125
git checkout "$COMMIT_BRANCH"
123126
124127
# Run script
125-
UPSTREAM_COMMIT=$(git rev-parse HEAD)
126128
"${SCRIPT_PATH}" "${SCRIPT_ARGS[@]}"
127129
128-
# Log changes
129-
DATA=".commits.json"
130-
cat << EOF > "$DATA"
131-
{
132-
"branch": {
133-
"source": "$TARGET_BRANCH",
134-
"source_sha": "$UPSTREAM_COMMIT",
135-
"target": "$COMMIT_BRANCH"
136-
},
137-
EOF
138-
echo -n ' "commits": [' >> "$DATA"
139-
140-
PREVIOUS_COMMIT=$UPSTREAM_COMMIT
141-
HEAD=$(git rev-parse HEAD)
142-
for COMMIT in $(git rev-list "$UPSTREAM_COMMIT..HEAD"); do
143-
git checkout "$COMMIT"
144-
if tail -1 "$DATA" | grep -q "}$" ; then
145-
echo ","
146-
else
147-
echo
148-
fi >> "$DATA"
149-
cat << EOF >> "$DATA"
150-
{
151-
"files": [
152-
EOF
153-
for FILE in $(git diff --name-only "$PREVIOUS_COMMIT..$COMMIT"); do
154-
if tail -1 "$DATA" | grep -q "}$" ; then
155-
echo "," >> "$DATA"
156-
fi
157-
echo " {" >> "$DATA"
158-
if [ -e "$FILE" ]; then
159-
cat << EOF >> "$DATA"
160-
"content": "$(cat "$FILE" | base64 | tr -d "\n")",
161-
"mode": "$(git ls-files --format='%(objectmode)' "$FILE")",
162-
EOF
163-
fi
164-
cat << EOF >> "$DATA"
165-
"path": "$FILE"
166-
EOF
167-
echo -n " }" >> "$DATA"
168-
done
169-
MESSAGE=$(git log -1 --format="%B" "$COMMIT" | sed "s:$:\\\n:g" | tr -d "\n") 2>/dev/null
170-
cat << EOF >> "$DATA"
171-
172-
],
173-
"message": "$MESSAGE"
174-
EOF
175-
echo -n " }" >> "$DATA"
176-
done
177-
if tail -1 "$DATA" | grep -q "\[$" ; then
178-
echo "],"
130+
# Push changes
131+
if ! git ls-remote --heads origin | grep -q "/$COMMIT_BRANCH$" \
132+
|| ! git diff --quiet "origin/$COMMIT_BRANCH" ; then
133+
git push --force --set-upstream origin "$COMMIT_BRANCH"
179134
else
180-
echo "
181-
],"
182-
fi >> "$DATA"
183-
cat << EOF >> "$DATA"
184-
"user": {
185-
"email": "$GIT_EMAIL",
186-
"name": "$GIT_USER"
187-
}
188-
}
189-
EOF
135+
echo "No changes"
136+
fi
190137
workspaces:
191138
- name: workdir
192139
description: Shared storage to keep a single copy of the repositories

.tekton/update-dependencies.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ spec:
2525
- name: source_branch
2626
value: "{{ source_branch }}"
2727
workspaces:
28+
- name: basic-auth
29+
workspace: basic-auth
30+
secret:
31+
secretName: "{{ git_auth_secret }}"
2832
- name: workdir
2933
volumeClaimTemplate:
3034
spec:

0 commit comments

Comments
 (0)