From 710fb701c7b0207846468551d89ae889f01e1793 Mon Sep 17 00:00:00 2001 From: Jonas_Jones Date: Fri, 20 Jun 2025 23:49:42 +0200 Subject: [PATCH 1/2] added github clone workflow --- .github/workflows/forgejo-mirror.yml | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/forgejo-mirror.yml diff --git a/.github/workflows/forgejo-mirror.yml b/.github/workflows/forgejo-mirror.yml new file mode 100644 index 0000000..ae050ea --- /dev/null +++ b/.github/workflows/forgejo-mirror.yml @@ -0,0 +1,45 @@ +name: Mirror Forgejo to GitHub + +on: + schedule: + - cron: '0 * * * *' # every hour + workflow_dispatch: + +env: + FORGEJO_OWNER: Jonas_Jones + +jobs: + mirror: + runs-on: ubuntu-latest + steps: + - name: Set GitHub owner and repo variables + id: vars + run: | + OWNER=$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f1) + REPO=$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f2) + echo "OWNER=$OWNER" >> $GITHUB_OUTPUT + echo "REPO=$REPO" >> $GITHUB_OUTPUT + + - name: Clone Forgejo repo and push branches and tags safely + env: + FORGEJO_OWNER: ${{ env.FORGEJO_OWNER }} + OWNER: ${{ steps.vars.outputs.OWNER }} + REPO: ${{ steps.vars.outputs.REPO }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + FORGEJO_URL="https://git.jonasjones.dev/${FORGEJO_OWNER}/${REPO}.git" + GITHUB_REPO_URL="https://x-access-token:${GITHUB_TOKEN}@github.com/${OWNER}/${REPO}.git" + + git clone --bare "$FORGEJO_URL" forgejo.git + cd forgejo.git + + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + git remote add github "$GITHUB_REPO_URL" + + # Push all branches without deleting any remote branch + git push github refs/heads/*:refs/heads/* + + # Push all tags + git push github refs/tags/*:refs/tags/* \ No newline at end of file From a7051622b57c66a846f22e20a97c30006caf58c2 Mon Sep 17 00:00:00 2001 From: Jonas_Jones Date: Fri, 20 Jun 2025 23:58:06 +0200 Subject: [PATCH 2/2] fixed git sync --- .github/workflows/forgejo-mirror.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/forgejo-mirror.yml b/.github/workflows/forgejo-mirror.yml index ae050ea..d85aefd 100644 --- a/.github/workflows/forgejo-mirror.yml +++ b/.github/workflows/forgejo-mirror.yml @@ -38,6 +38,8 @@ jobs: git remote add github "$GITHUB_REPO_URL" + git pull + # Push all branches without deleting any remote branch git push github refs/heads/*:refs/heads/*