Skip to content

☀ projected k8s-manifests-github from e741ca3 #27

☀ projected k8s-manifests-github from e741ca3

☀ projected k8s-manifests-github from e741ca3 #27

Workflow file for this run

name: 'K8s: Prepare k8s-manifests Deploy PR'
on:
push:
branches: [ releases/k8s-manifests ]
env:
BRANCH_RELEASE: releases/k8s-manifests
BRANCH_DEPLOY: deploys/k8s-manifests
jobs:
k8s-prepare:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ env.BRANCH_RELEASE }}
- name: Configure .kube/config
run: |
test -e ~/.kube || mkdir ~/.kube
echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > ~/.kube/config
- name: Install kubectl-neat-diff
run: |
sudo wget https://github.com/sh0rez/kubectl-neat-diff/releases/download/v0.1.0/kubectl-neat-diff-linux-amd64 -O /usr/local/bin/kubectl-neat-diff
sudo chmod +x /usr/local/bin/kubectl-neat-diff
echo "KUBECTL_EXTERNAL_DIFF=kubectl-neat-diff" >> $GITHUB_ENV
- name: Generate diff
run: |
(
find . \
-maxdepth 1 \
-type d \
-not -name '.*' \
-print0 \
| sort -z \
| xargs -r0 -n 1 kubectl diff -Rf || true
) > /tmp/kube.diff
- name: Create/update pull request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
## 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
\`kubectl diff\` reports that applying ${pr_head_describe} will change:
\`\`\`diff
$(if (( diff_size > 50000)); then echo 'diff too big; review locally'; else cat /tmp/kube.diff; fi)
\`\`\`
EOF
)"
## generate initial commit for base if needed
if ! git ls-remote --exit-code --heads origin "${BRANCH_DEPLOY}"; then
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
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
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
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
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}