From 6451737621fd731d9d7cce2e48f4e826fcfa1ee3 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Thu, 10 Oct 2024 14:13:12 -0400 Subject: [PATCH] Initial mirror workflow --- .forgejo/workflows/mirror-repository.yml | 51 ++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .forgejo/workflows/mirror-repository.yml diff --git a/.forgejo/workflows/mirror-repository.yml b/.forgejo/workflows/mirror-repository.yml new file mode 100644 index 000000000000..b711bf6f9f92 --- /dev/null +++ b/.forgejo/workflows/mirror-repository.yml @@ -0,0 +1,51 @@ +on: + workflow_dispatch: + + schedule: + - cron: '@hourly' + +jobs: + mirror: + name: Pull from upstream + runs-on: x86_64 + container: + image: alpine:latest + env: + upstream: https://github.com/electron/electron + tags: 'v*' + steps: + - name: Environment setup + run: apk add grep git sed coreutils bash nodejs + - name: Fetch destination + uses: actions/checkout@v4 + with: + fetch_depth: 1 + ref: ci + token: ${{ secrets.CODE_FORGEJO_TOKEN }} + - name: Missing tag detecting + run: | + git ls-remote $upstream "refs/tags/$tags" | grep -v '{' | sed 's|.*/||' > upstream_tags + git ls-remote ${{ github.server_url}}/${{ github.repository }} "refs/tags/$tags" | grep -v '{' | sed 's|.*/||' > destination_tags + cat upstream_tags destination_tags | tr ' ' '\n' | sort | uniq -u > missing_tags + echo "Missing tags:" + cat missing_tags + - name: Missing tag fetch + run: | + git remote add upstream $upstream + while read tag; do + git fetch upstream tag $tag --no-tags + done < missing_tags + - name: Packaging workflow injection + run: | + while read tag; do + git checkout $tag + git tag -d $tag + git checkout ci -- ./.forgejo + git config user.name "forgejo-actions[bot]" + git config user.email "dev@ayakael.net" + git commit -m 'Inject custom workflow' + git tag -a $tag -m $tag + done < missing_tags + - name: Push to destination + run: git push --force origin refs/tags/*:refs/tags/* --tags +