Update .gitea/workflows/deploy-ci.yaml
This commit is contained in:
@@ -12,12 +12,13 @@ env:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
fetch-template:
|
fetch-template:
|
||||||
name: Fetch CI Template
|
name: Fetch CI Template and .gitattributes
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: ${{ vars.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
image: ${{ vars.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||||
outputs:
|
outputs:
|
||||||
template_b64: ${{ steps.load-template.outputs.template_b64 }}
|
template_b64: ${{ steps.load-template.outputs.template_b64 }}
|
||||||
|
gitattributes_b64: ${{ steps.load-gitattributes.outputs.gitattributes_b64 }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Mask Sensitive Token
|
- name: Mask Sensitive Token
|
||||||
@@ -30,11 +31,21 @@ jobs:
|
|||||||
echo "📥 Fetching template from osc/skins-template@$TEMPLATE_PATH"
|
echo "📥 Fetching template from osc/skins-template@$TEMPLATE_PATH"
|
||||||
resp=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" \
|
resp=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" \
|
||||||
"$GITEA_API/repos/osc/skins-template/contents/$TEMPLATE_PATH?ref=main")
|
"$GITEA_API/repos/osc/skins-template/contents/$TEMPLATE_PATH?ref=main")
|
||||||
|
|
||||||
template_b64=$(echo "$resp" | jq -r .content)
|
template_b64=$(echo "$resp" | jq -r .content)
|
||||||
echo "✅ Template fetched and encoded"
|
echo "✅ Template fetched and encoded"
|
||||||
echo "template_b64=$template_b64" >> $GITHUB_OUTPUT
|
echo "template_b64=$template_b64" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- id: load-gitattributes
|
||||||
|
name: Load .gitattributes from osc/skins-template
|
||||||
|
run: |
|
||||||
|
set -eo pipefail
|
||||||
|
echo "📥 Fetching .gitattributes from osc/skins-template"
|
||||||
|
resp=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" \
|
||||||
|
"$GITEA_API/repos/osc/skins-template/contents/.gitattributes?ref=main")
|
||||||
|
gitattributes_b64=$(echo "$resp" | jq -r .content)
|
||||||
|
echo "✅ .gitattributes fetched and encoded"
|
||||||
|
echo "gitattributes_b64=$gitattributes_b64" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
discover-repositories:
|
discover-repositories:
|
||||||
name: Discover Valid Skin Repositories
|
name: Discover Valid Skin Repositories
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -100,7 +111,7 @@ jobs:
|
|||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
sync-template:
|
sync-template:
|
||||||
name: Sync CI Template
|
name: Sync CI Template and .gitattributes
|
||||||
needs: [fetch-template, discover-repositories]
|
needs: [fetch-template, discover-repositories]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
@@ -118,7 +129,7 @@ jobs:
|
|||||||
echo "🗂️ Repositories to process:"
|
echo "🗂️ Repositories to process:"
|
||||||
cat "${{ env.REPO_LIST_FILE }}"
|
cat "${{ env.REPO_LIST_FILE }}"
|
||||||
|
|
||||||
- name: Apply Template to Repositories
|
- name: Apply Template and .gitattributes to Repositories
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
@@ -128,32 +139,40 @@ jobs:
|
|||||||
owner="${repo_full%%/*}"
|
owner="${repo_full%%/*}"
|
||||||
repo="${repo_full##*/}"
|
repo="${repo_full##*/}"
|
||||||
api="$GITEA_API/repos/$owner/$repo"
|
api="$GITEA_API/repos/$owner/$repo"
|
||||||
|
echo "🔧 Syncing CI and .gitattributes to: $owner/$repo"
|
||||||
echo "🔧 Syncing CI to: $owner/$repo"
|
|
||||||
|
|
||||||
default_branch=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "$api" | jq -r '.default_branch')
|
default_branch=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "$api" | jq -r '.default_branch')
|
||||||
url="$api/contents/$TEMPLATE_PATH"
|
|
||||||
|
for file in "$TEMPLATE_PATH" ".gitattributes"; do
|
||||||
|
if [[ "$file" == "$TEMPLATE_PATH" ]]; then
|
||||||
|
content="${{ needs.fetch-template.outputs.template_b64 }}"
|
||||||
|
msg="Update CI from skins-template"
|
||||||
|
else
|
||||||
|
content="${{ needs.fetch-template.outputs.gitattributes_b64 }}"
|
||||||
|
msg="Update .gitattributes from skins-template"
|
||||||
|
fi
|
||||||
|
|
||||||
|
url="$api/contents/$file"
|
||||||
sha=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "$url" | jq -r '.sha // empty' || true)
|
sha=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "$url" | jq -r '.sha // empty' || true)
|
||||||
|
|
||||||
if [[ -z "$sha" ]]; then
|
if [[ -z "$sha" ]]; then
|
||||||
action="Add"
|
action="Add"
|
||||||
msg="Add CI from skins-template"
|
payload=$(jq -nc --arg message "$msg" --arg content "$content" --arg branch "$default_branch" \
|
||||||
payload=$(jq -nc --arg message "$msg" --arg content "${{ needs.fetch-template.outputs.template_b64 }}" --arg branch "$default_branch" \
|
|
||||||
'{message: $message, content: $content, branch: $branch}')
|
'{message: $message, content: $content, branch: $branch}')
|
||||||
else
|
else
|
||||||
action="Update"
|
action="Update"
|
||||||
msg="Update CI from skins-template"
|
payload=$(jq -nc --arg message "$msg" --arg content "$content" --arg sha "$sha" --arg branch "$default_branch" \
|
||||||
payload=$(jq -nc --arg message "$msg" --arg content "${{ needs.fetch-template.outputs.template_b64 }}" --arg sha "$sha" --arg branch "$default_branch" \
|
|
||||||
'{message: $message, content: $content, sha: $sha, branch: $branch}')
|
'{message: $message, content: $content, sha: $sha, branch: $branch}')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if curl -sSL --fail -X PUT -H "Authorization: token ${{ secrets.TOKEN }}" -H "Content-Type: application/json" \
|
if curl -sSL --fail -X PUT -H "Authorization: token ${{ secrets.TOKEN }}" -H "Content-Type: application/json" \
|
||||||
-d "$payload" "$url" >/dev/null; then
|
-d "$payload" "$url" >/dev/null; then
|
||||||
echo "✅ $action successful for $owner/$repo on branch $default_branch"
|
echo "✅ $action successful for $file in $owner/$repo"
|
||||||
else
|
else
|
||||||
echo "❌ $action failed for $owner/$repo" >&2
|
echo "❌ $action failed for $file in $owner/$repo" >&2
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
done
|
||||||
|
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
run: rm -f "${{ env.REPO_LIST_FILE }}"
|
run: rm -f "${{ env.REPO_LIST_FILE }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user