Skip to content

Commit fce7a60

Browse files
patchback[bot]himdelnewswangerd
authored
update_manifest workflow: fix & use deploy_key instead of user token (#973) (#999)
* ci workflow: fix update_manifest update_manifest is currently failing to run for 2 reasons: GITHUB_PULL_REQUEST is set to a PR number during the pull_request event, and nothing during the push event, the script expects `false` fixing by testing GITHUB_PULL_REQUEST for nonempty GITHUB_BRANCH is set to github.head_ref, only available during pull_request events, the script tests for "master" or "stable" fixing by updating GITHUB_BRANCH to use github.ref sans the refs/heads/ prefix and removed the unused vars, as well as github.event.after which doesn't seem documented for push builds * update_manifest: use deploy key instead of user token same as ansible/ansible-hub-ui#946 the gpg-encrypted key is added to the repo, encrypted by a passphrase added to secrets No-Issue * post-job-template.yml.j2 - update and rerun `plugin-template --github galaxy_ng` (cherry picked from commit 436ffc4) Co-authored-by: Martin Hradil <mhradil@redhat.com> Co-authored-by: David Newswanger <dnewswan@redhat.com>
1 parent 23c2f49 commit fce7a60

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

.github/post-job-template.yml.j2

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ update_manifest:
66
- name: Checkout code
77
uses: actions/checkout@v2
88
with:
9-
ref: {{ "${{ github.event.after }}" }} # for PR avoids checking out merge commit
109
fetch-depth: 0 # include all history
1110

11+
- name: "Set GITHUB_BRANCH"
12+
run: |
13+
GITHUB_BRANCH=`sed 's/^refs\/heads\///' <<< $GITHUB_REF`
14+
echo "GITHUB_BRANCH=${GITHUB_BRANCH}" >> $GITHUB_ENV
15+
1216
- name: Update Manifest for Ansible Hub UI
1317
env:
14-
{{ set_env_vars() | indent(10) }}
18+
GITHUB_PULL_REQUEST: {{ "${{ github.event.number }}" }}
19+
MANIFEST_PASSPHRASE: {{ "${{ secrets.MANIFEST_PASSPHRASE }}" }}
1520
run: .github/workflows/scripts/update_manifest.sh
1621
shell: bash

.github/workflows/ci.yml

+6-8
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,16 @@ jobs:
198198
- name: Checkout code
199199
uses: actions/checkout@v2
200200
with:
201-
ref: ${{ github.event.after }} # for PR avoids checking out merge commit
202201
fetch-depth: 0 # include all history
203202

203+
- name: "Set GITHUB_BRANCH"
204+
run: |
205+
GITHUB_BRANCH=`sed 's/^refs\/heads\///' <<< $GITHUB_REF`
206+
echo "GITHUB_BRANCH=${GITHUB_BRANCH}" >> $GITHUB_ENV
207+
204208
- name: Update Manifest for Ansible Hub UI
205209
env:
206-
PY_COLORS: '1'
207-
ANSIBLE_FORCE_COLOR: '1'
208210
GITHUB_PULL_REQUEST: ${{ github.event.number }}
209-
GITHUB_PULL_REQUEST_BODY: ${{ github.event.pull_request.body }}
210-
GITHUB_BRANCH: ${{ github.head_ref }}
211-
GITHUB_REPO_SLUG: ${{ github.repository }}
212-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
213-
GITHUB_CONTEXT: ${{ github.event.pull_request.commits_url }}
211+
MANIFEST_PASSPHRASE: ${{ secrets.MANIFEST_PASSPHRASE }}
214212
run: .github/workflows/scripts/update_manifest.sh
215213
shell: bash
2.02 KB
Binary file not shown.

.github/workflows/scripts/update_manifest.sh

+10-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ readonly GITHUB_BRANCH="${GITHUB_BRANCH:-}"
1010

1111
readonly MANIFESTS_GIT_USER="${MANIFESTS_GIT_USER:-}"
1212
readonly MANIFESTS_GIT_EMAIL="${MANIFESTS_GIT_EMAIL:-}"
13-
readonly MANIFESTS_GIT_TOKEN="${MANIFESTS_GIT_TOKEN:-}"
14-
readonly MANIFESTS_GIT_URL="https://${MANIFESTS_GIT_USER}:${MANIFESTS_GIT_TOKEN}@github.com/RedHatInsights/manifests.git"
13+
readonly MANIFESTS_GIT_URL="git@github.com:RedHatInsights/manifests.git"
1514

1615
readonly MANIFESTS_DIR='/tmp/manifests'
1716
readonly MANIFEST_FILE="${MANIFESTS_DIR}/automation-hub/automation-hub-api.txt"
@@ -37,7 +36,7 @@ generate_docker_manifest() {
3736
echo "${PREFIX}/Dockerfile-FROM-${base_image}"
3837
}
3938

40-
if [[ "$GITHUB_PULL_REQUEST" != 'false' ]]; then
39+
if [[ -n "$GITHUB_PULL_REQUEST" ]]; then
4140
log_message 'Ignoring manifest update for pull request.'
4241
exit 0
4342
fi
@@ -49,6 +48,14 @@ else
4948
exit 0
5049
fi
5150

51+
# decrypt deploy key and use
52+
gpg --quiet --batch --yes --decrypt --passphrase="$MANIFEST_PASSPHRASE" --output .github/workflows/scripts/deploy_manifest .github/workflows/scripts/deploy_manifest.gpg
53+
54+
chmod 600 .github/workflows/scripts/deploy_manifest
55+
eval `ssh-agent -s`
56+
ssh-add .github/workflows/scripts/deploy_manifest
57+
58+
5259
git clone --depth=10 --branch="${manifests_branch}" \
5360
"${MANIFESTS_GIT_URL}" "${MANIFESTS_DIR}" &>/dev/null
5461

0 commit comments

Comments
 (0)