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