Skip to content

Commit

Permalink
Merge pull request #95 from CodeForPhilly/releases/k8s-manifests
Browse files Browse the repository at this point in the history
Deploy releases/k8s-manifests 214edd5
  • Loading branch information
themightychris authored Nov 22, 2023
2 parents 07bbc00 + 214edd5 commit 5162131
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 25 deletions.
34 changes: 24 additions & 10 deletions .github/workflows/k8s-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# format comment
pr_comment="$(cat <<EOF
## build comment body
echo
echo "Builing coment body content..."
comment_body="$(cat <<EOF
\`kubectl apply\` output (excluding unchanged) for $(git describe --always --tag) was:
\`\`\`
Expand All @@ -112,14 +114,26 @@ jobs:
)"
# get last PR
last_pr_number=$(hub pr list -s merged -b "${BRANCH_DEPLOY}" -h "${BRANCH_RELEASE}" -f '%I' -L 1)
# post comment
if [ -n "${last_pr_number}" ]; then
echo "Adding comment to PR #${last_pr_number}"
hub api "/repos/${GITHUB_REPOSITORY}/issues/${last_pr_number}/comments" -f body="${pr_comment}"
## get most recent merged PR
echo
echo "Looking for most recent merged PR for branch ${BRANCH_RELEASE}..."
pr_number=$(
gh pr list \
--head "${BRANCH_RELEASE}" \
--base "${BRANCH_DEPLOY}" \
--state merged \
--limit 1 \
--json number \
--jq '.[0].number'
)
## post comment
if [ -n "${pr_number}" ]; then
echo
echo "Adding comment to PR #${pr_number}..."
gh pr comment "${pr_number}" \
--body "${comment_body}"
fi
# - uses: mxschmitt/action-tmate@v3
Expand Down
57 changes: 43 additions & 14 deletions .github/workflows/k8s-prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# build PR description body
diff_size=$(stat -c%s /tmp/kube.diff)
## build PR description body
echo
echo "Builing PR title+body content..."
diff_size=$(du -k '/tmp/kube.diff' | cut -f1)
pr_head_describe="$(git describe --always --tag)"
pr_title="Deploy ${BRANCH_RELEASE} ${pr_head_describe}"
pr_body="$(cat <<EOF
Deploy ${BRANCH_RELEASE} ${pr_head_describe}
\`kubectl diff\` reports that applying ${pr_head_describe} will change:
\`\`\`diff
Expand All @@ -63,23 +64,51 @@ jobs:
)"
# generate initial commit for base if needed
## generate initial commit for base if needed
if ! git ls-remote --exit-code --heads origin "${BRANCH_DEPLOY}"; then
git fetch origin --unshallow
_first_projected_commit=$(git rev-list --max-parents=0 --first-parent HEAD)
git push origin "${_first_projected_commit}:refs/heads/${BRANCH_DEPLOY}"
echo
echo "Existing branch ${BRANCH_DEPLOY} not found, generating initial commit..."
git fetch origin --unshallow
_first_projected_commit=$(git rev-list --max-parents=0 --first-parent HEAD)
git push origin "${_first_projected_commit}:refs/heads/${BRANCH_DEPLOY}"
fi
# check for existing PR
_existing_pr_number=$(hub pr list -h "${BRANCH_RELEASE}" -f '%I')
## check for existing PR
echo
echo "Looking for existing open PR for branch ${BRANCH_RELEASE}..."
_existing_pr_number=$(
gh pr list \
--head "${BRANCH_RELEASE}" \
--base "${BRANCH_DEPLOY}" \
--state open \
--limit 1 \
--json number \
--jq '.[0].number'
)
if [ -n "${_existing_pr_number}" ]; then
echo "Updating PR #${_existing_pr_number}"
hub issue update "${_existing_pr_number}" -F <(echo "${pr_body}")
echo
echo "Found existing PR #${_existing_pr_number}, updating description..."
pr_url=$(
gh api "/repos/${GITHUB_REPOSITORY}/pulls/${_existing_pr_number}" \
--field title="${pr_title}" \
--field body="${pr_body}" \
--jq '.url'
)
echo "Updated PR: ${pr_url}"
else
echo "Opening PR"
hub pull-request -b "${BRANCH_DEPLOY}" -h "${BRANCH_RELEASE}" -F <(echo "${pr_body}") > /tmp/pr.json
echo
echo "Opening PR..."
pr_url=$(
gh pr create \
--base "${BRANCH_DEPLOY}" \
--head "${BRANCH_RELEASE}" \
--title "${pr_title}" \
--body "${pr_body}"
)
pr_number="${pr_url##*/}"
echo "Opened PR #${pr_number}"
fi
# - uses: mxschmitt/action-tmate@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ spec:
- ReadWriteOnce
resources:
requests:
storage: 15Gi
storage: 30Gi

0 comments on commit 5162131

Please sign in to comment.