Skip to content

Commit

Permalink
Merge pull request #1012 from ErikJiang/update_spray_artifact_patch_ci
Browse files Browse the repository at this point in the history
update kubespray artifact patch CI
  • Loading branch information
ErikJiang authored Nov 19, 2023
2 parents a03d7fc + b098fa7 commit 20fe63f
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/manual-kubespray-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ jobs:
mkdir manifest && cp charts/kubean/templates/manifest.cr.yaml manifest/manifest-${{ needs.check-inputs.outputs.tag }}.yml
echo "manifest cr output:"
cat manifest/manifest-${{ needs.check-inputs.outputs.tag }}.yml
rm -rf kubespray/
- name: Push Kubean manifest to another repository
env:
REPO_OWNER: ${{ github.repository_owner }}
Expand All @@ -198,6 +199,26 @@ jobs:
run: |
./hack/sync-manifest.sh
- name: Generate artifacts patch markdown doc
env:
IMAGE_REPO: ${{ needs.check-inputs.outputs.image_repo }}
run: |
python artifacts/gen_artifact_patch_md.py
mv artifacts.md docs/overrides/artifacts.md
- name: Push artifact patch md
id: push_directory
uses: cpina/[email protected]
env:
SSH_DEPLOY_KEY: ${{ secrets.SYNC_RLS_PRIVATE_KEY }}
with:
source-directory: .
destination-github-username: ${{ github.repository_owner }}
destination-repository-name: kubean
user-email: kubean-robot@kubean-io
commit-message: Update artifacts.md, See ORIGIN_COMMIT from $GITHUB_REF
target-branch: main

show-artifacts:
needs: [check-inputs, build-kubespray-image, build-sprayjob-image, build-airgap-patch-image, gen-manifest]
runs-on: ubuntu-latest
Expand Down
84 changes: 84 additions & 0 deletions artifacts/gen_artifact_patch_md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env python

import subprocess
import yaml
import os
from jinja2 import Template
from datetime import datetime

IMAGE_REPO = os.getenv("IMAGE_REPO", default="kubean-io")

KUBEAN_PATCH_TEMPLATE = '''
{% for release, infos in releases.items() %}
### ▶️ release-{{ release }}
> ⚓ kube_version range: [ {{ infos[0].kube_version_range[infos[0].kube_version_range|length-1] }} ~ {{ infos[0].kube_version_range[0] }} ]
<table>
<thead>
<tr>
<th>Commit Date</th>
<th>Artifacts</th>
</tr>
</thead>
{% for info in infos %}
<tbody>
<tr>
<td rowspan=3> 📅 {{ info.commit_date }} </td>
<td rowspan=1>
📝 <a href="https://raw.githubusercontent.com/{{ repo_name }}/kubean-manifest/main/manifests/manifest-{{ release }}-{{ info.commit_short_sha }}.yml">manifest-{{ release }}-{{ info.commit_short_sha }}.yml</a>
</td>
</tr>
<tr>
<td rowspan=1> 📦 {{ image_registry }}/{{ repo_name }}/spray-job:{{ release }}-{{ info.commit_short_sha }} </td>
</tr>
<tr>
<td rowspan=1> 📦 {{ image_registry }}/{{ repo_name }}/airgap-patch:{{ release }}-{{ info.commit_short_sha }} </td>
</tr>
</tbody>
{% endfor %}
</table>
{% endfor %}
'''


if __name__ == '__main__':

repo_name="kubean-manifest"
subprocess.getoutput(f"git clone https://github.com/{IMAGE_REPO}/{repo_name}.git")
manifests_path=f'{repo_name}/manifests'

manifest_files = subprocess.getoutput(f"ls {manifests_path}")

release_keys=['2.21', '2.22', '2.23']
releases = {key: [] for key in release_keys}
for manifest in manifest_files.splitlines():
for key in release_keys:
if key in manifest:
with open(f'{manifests_path}/{manifest}', 'r') as stream:
data = yaml.safe_load(stream)
commit_short_sha = data.get('metadata', {}).get('annotations', {}).get('kubean.io/sprayCommit')
commit_timestamp = int(data.get('metadata', {}).get('annotations', {}).get('kubean.io/sprayTimestamp'))
commit_date = datetime.fromtimestamp(commit_timestamp)
components = data.get('spec', {}).get('components', {})
kube_info = next(item for item in data.get('spec', {}).get('components', {}) if item['name'] == 'kube')
kube_version_range = kube_info.get('versionRange', [])
releases[key].append({
'commit_short_sha': commit_short_sha,
'commit_timestamp': commit_timestamp,
'commit_date': commit_date,
'kube_version_range': kube_version_range})

# print(f'releases: {releases}')

for key in release_keys:
releases[key].sort(key=lambda item:item['commit_timestamp'], reverse=True)

t = Template(KUBEAN_PATCH_TEMPLATE)
md_contents = t.render(releases=releases, image_registry='ghcr.io', repo_name=IMAGE_REPO)
# print(md_contents)

artifact_md = open('artifacts.md', 'w')
artifact_md.write(md_contents)
artifact_md.close()

subprocess.getoutput(f"rm -rf {repo_name}")
2 changes: 1 addition & 1 deletion hack/sync-manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ chmod 600 "$DEPLOY_KEY_FILE"
SSH_KNOWN_HOSTS_FILE="$HOME/.ssh/known_hosts"
ssh-keyscan -H "${GITHUB_SERVER}" > "$SSH_KNOWN_HOSTS_FILE"

export GIT_SSH_COMMAND="ssh -i "$DEPLOY_KEY_FILE" -o UserKnownHostsFile=$SSH_KNOWN_HOSTS_FILE"
export GIT_SSH_COMMAND="ssh -i ${DEPLOY_KEY_FILE} -o UserKnownHostsFile=$SSH_KNOWN_HOSTS_FILE"

GIT_CMD_REPOSITORY="git@${GITHUB_SERVER}:${REPO_OWNER}/${DST_REPO}.git"
git clone --single-branch --depth 1 --branch "$DST_BRANCH" "$GIT_CMD_REPOSITORY" "$TMP_DIR"
Expand Down

0 comments on commit 20fe63f

Please sign in to comment.