Automatic
documentation update
#96
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Pull mirrors from database" | |
on: | |
push: | |
branches: | |
- master | |
workflow_dispatch: | |
jobs: | |
Build: | |
name: "Pull" | |
runs-on: ubuntu-24.04 | |
if: ${{ github.repository_owner == 'armbian' }} | |
steps: | |
- name: Checkout main documentation | |
uses: actions/checkout@v4 | |
with: | |
repository: 'armbian/documentation' | |
path: 'documentation' | |
- name: Update rsync section | |
run: | | |
FILE="documentation/docs/Mirrors.md" | |
sed '/^### 2\. Set up synchronization via rsync/,$d' "$FILE" > tmp.md | |
cat <<EOF >> tmp.md | |
### 2. Set up synchronization via rsync | |
- Sync files from one of the official repositories using the following commands: | |
| Content | Command | Required Space | | |
|-----------------|---------------------------------------------|---------------:| | |
EOF | |
for storage in dl apt archive oldarchive; do | |
size=$(curl -s https://k-space.ee.armbian.com/$storage/size.txt) | |
case "$storage" in | |
"dl") | |
TEXT="Current images" | |
;; | |
"apt") | |
TEXT="Packages" | |
;; | |
"archive") | |
TEXT="Archived images" | |
;; | |
*) | |
TEXT="Very old images" | |
;; | |
esac | |
echo " | $TEXT | \`rsync -av rsync://rsync.armbian.com/$storage\` | $size |" >> tmp.md | |
done | |
sed -n '/^## Current Mirrors/,$p' "$FILE" >> tmp.md | |
sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' tmp.md | |
mv tmp.md "$FILE" | |
- name: Update Current Mirrors section | |
run: | | |
FILE="documentation/docs/Mirrors.md" | |
sed '/^## Current Mirrors/,$d' "$FILE" > tmp.md | |
cat <<EOF >> tmp.md | |
## Current Mirrors | |
| Site | Time Zone | Flag | Speed | Packages | Images | Archive | Rsync | | |
|:-----|:----------|------|-------:|:--------:|:------:|:-------:|:-----:| | |
EOF | |
JQ=$(curl -s -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" \ | |
-H "Accept: application/json; indent=4" \ | |
"${{ secrets.NETBOX_API }}/virtualization/virtual-machines/?limit=500&name__empty=false&role=mirror") | |
for i in $(echo $JQ | jq '.results[] | .id'); do | |
NAME=$(echo $JQ | jq ".results[] | select(.id == $i) | .name" | sed "s/\"//g") | |
SITE_ID=$(echo $JQ | jq ".results[] | select(.id == $i) | .site.id") | |
SITE_STATUS=$(echo $JQ | jq -r ".results[] | select(.id == $i) | .status.value") | |
SITE_TAGS=$(echo $JQ | jq -r ".results[] | select(.id == $i) | .tags[].slug" | xargs ) | |
SITEQ=$(curl -s -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" \ | |
-H "Accept: application/json; indent=4" \ | |
"${{ secrets.NETBOX_API }}/dcim/sites/?limit=500&name__empty=false&id=$SITE_ID") | |
SITE_NAME=$(echo $SITEQ | jq -r ".results[] | select(.id == $SITE_ID) | .name" | sed 's/ /\ /g') | |
SITE_REGION=$(echo $SITEQ | jq -r ".results[] | select(.id == $SITE_ID) | .region.display") | |
SITE_TZ=$(echo $SITEQ | jq -r ".results[] | select(.id == $SITE_ID) | .time_zone") | |
SITE_LATITUDE=$(echo $SITEQ | jq ".results[] | select(.id == $SITE_ID) | .latitude") | |
SITE_LONGITUDE=$(echo $SITEQ | jq ".results[] | select(.id == $SITE_ID) | .longitude") | |
SITE_SPEED=$(echo $SITEQ | jq -r ".results[] | select(.id == $SITE_ID) | .custom_fields.download_speed") | |
IP=$(dig +short "${NAME}" | tail -1) | |
SITE_FLAG=$(curl --max-time 5 -s http://ipwhois.app/json/"${IP}" | jq -r '.country_code') | |
[[ $SITE_STATUS == "decommissioning" ]] && continue | |
if [[ $SITE_STATUS != "active" ]]; then | |
LABEL=":x:" | |
else | |
LABEL=":white_check_mark:" | |
fi | |
if [[ "${SITE_TAGS}" == *"debs"* ]]; then FIELD1="$LABEL"; else FIELD1=""; fi | |
if [[ "${SITE_TAGS}" == *"images"* ]]; then FIELD2="$LABEL"; else FIELD2=""; fi | |
if [[ "${SITE_TAGS}" == *"archive"* ]]; then FIELD3="$LABEL"; else FIELD3=""; fi | |
if [[ "${SITE_TAGS}" == *"rsync"* ]]; then FIELD4="$LABEL"; else FIELD4=""; fi | |
echo "| [$SITE_NAME](https://$NAME) | $SITE_TZ | [](https://www.openstreetmap.org/search?lat=$SITE_LATITUDE&lon=$SITE_LONGITUDE) | $SITE_SPEED Mbps | $FIELD1 | $FIELD2 | $FIELD3 | $FIELD4 |" >> tmp.md | |
sleep 1 | |
done | |
sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' tmp.md | |
mv tmp.md "$FILE" | |
- name: Create Pull Request to documentation | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
path: documentation | |
commit-message: '`Automatic` documentation update' | |
signoff: false | |
branch: auto-update-docs | |
delete-branch: true | |
title: '`Automatic` documentation update' | |
body: | | |
Generate documentation. | |
labels: | | |
Needs review | |
#assignees: igorpecovnik | |
#reviewers: Must be org collaborator | |
draft: false |