diff --git a/.gitea/workflows/update_readme.yml b/.gitea/workflows/update_readme.yml new file mode 100644 index 0000000..5e562d0 --- /dev/null +++ b/.gitea/workflows/update_readme.yml @@ -0,0 +1,96 @@ +name: Update README + +# Allow Gitea Actions to commit and push changes +permissions: + contents: write + +on: + workflow_dispatch: + schedule: + - cron: '0 4 * * *' # Every day at 4 AM UTC + +jobs: + update-readme: + runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:act-latest + + env: + # Adjusted for Gitea profile convention (usually owner/.profile or owner/.gitea) + # Please verify if 'ivancarlos/.profile' exists or adjust to your profile repository. + SOURCE_REPO: ivancarlos/.profile + SOURCE_BRANCH: main + + steps: + - name: Checkout current repository + uses: actions/checkout@v4 + + - name: Checkout source README template + uses: actions/checkout@v4 + with: + repository: ${{ env.SOURCE_REPO }} + ref: ${{ env.SOURCE_BRANCH }} + path: source_readme + + - name: Update README.md (buttons and footer) + run: | + set -e + REPO_NAME="${GITHUB_REPOSITORY##*/}" + + # --- Extract buttons block from source --- + # Checking if source file exists, if not, skip or fail. + if [ ! -f source_readme/README.md ]; then + echo "Source README not found in ${SOURCE_REPO}" + exit 1 + fi + + BUTTONS=$(awk '//{flag=1;next}//{flag=0}flag' source_readme/README.md) + BUTTONS_UPDATED=$(echo "$BUTTONS" | sed "s/\.github/${REPO_NAME}/g") + + # --- Extract footer block from source (everything from onward) --- + FOOTER=$(awk '//{flag=1}flag' source_readme/README.md) + + # --- Replace buttons section in README.md --- + UPDATED=$(awk -v buttons="$BUTTONS_UPDATED" ' + BEGIN { skip=0 } + // { + print + print buttons + skip=1 + next + } + // && skip { + print + print buttons + skip=0 + next + } + !skip { print } + ' README.md) + + # --- Replace everything after with FOOTER --- + echo "$UPDATED" | awk -v footer="$FOOTER" ' + // { + print footer + found=1 + exit + } + { print } + ' > README.tmp && mv README.tmp README.md + + - name: Remove source_readme from git index + run: rm -rf source_readme || true + + - name: Commit and push changes + run: | + git config --global --add safe.directory '*' + git config user.name "Gitea Actions" + git config user.email "actions@git.icc.gg" + + if [ -n "$(git status --porcelain README.md)" ]; then + git add README.md + git commit -m "Sync README from template [▶️]" + git push origin HEAD:${{ github.ref_name }} + else + echo "No changes to README.md" + fi