diff --git a/.github/workflows/sync-to-forgejo.yml b/.github/workflows/sync-to-forgejo.yml index 354a407..07b6182 100644 --- a/.github/workflows/sync-to-forgejo.yml +++ b/.github/workflows/sync-to-forgejo.yml @@ -5,36 +5,34 @@ on: branches: - main - high-performance + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: sync-to-forgejo-${{ github.ref }} + cancel-in-progress: true jobs: sync: runs-on: ubuntu-latest - permissions: - contents: read steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Push branch to Forgejo + - name: Configure Git + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Push to Forgejo env: - FORGEJO_SECRET: ${{ secrets.FORGEJO_SECRET || secrets.GITEA_SECRET }} - FORGEJO_OWNER: ${{ secrets.FORGEJO_OWNER || 'ashwin' }} - FORGEJO_USERNAME: ${{ secrets.FORGEJO_USERNAME || secrets.GITEA_USERNAME || 'ashwin' }} - REPO: ${{ github.event.repository.name }} - BRANCH: ${{ github.ref_name }} + FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }} run: | set -euo pipefail - test -n "${FORGEJO_SECRET:-}" || { echo "FORGEJO_SECRET is empty"; exit 1; } - - AUTH="$(printf '%s' "${FORGEJO_USERNAME}:${FORGEJO_SECRET}" | base64 -w0)" - TARGET="https://ci.nxtgauge.com/${FORGEJO_OWNER}/${REPO}.git" - - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git remote remove forgejo 2>/dev/null || true - git remote add forgejo "${TARGET}" - - git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" push forgejo "HEAD:${BRANCH}" --force - git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" push forgejo --tags --force + git remote add forgejo "https://admin:${FORGEJO_TOKEN}@ci.nxtgauge.com/ashwin/${{ github.event.repository.name }}.git" 2>/dev/null || \ + git remote set-url forgejo "https://admin:${FORGEJO_TOKEN}@ci.nxtgauge.com/ashwin/${{ github.event.repository.name }}.git" + git push forgejo "HEAD:${GITHUB_REF#refs/heads/}" --force