Git Mirrors #2161
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Git Mirrors" | |
on: | |
# TODO: `on: push` is only for quick debugging | |
push: | |
branches: | |
- master | |
paths: | |
- ".github/actions/git-mirror/index.js" | |
- ".github/workflows/git-mirrors.yml" | |
schedule: | |
- cron: '44 * * * *' | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }} | |
jobs: | |
'mirror': | |
# continue-on-error: true | |
strategy: | |
max-parallel: 3 | |
fail-fast: false | |
matrix: | |
'json': | |
- | | |
{ | |
"name": "beautifulsoup" | |
} | |
- | | |
{ | |
"name": "miredo" | |
} | |
- | | |
{ | |
"name": "turnip" | |
} | |
- | | |
{ | |
"name": "launchpad" | |
} | |
- | | |
{ | |
"name": "inkscape" | |
} | |
- | | |
{ | |
"name": "mkvtoolnix" | |
} | |
- | | |
{ | |
"name": "graphviz" | |
} | |
# - | | |
# { | |
# "name": "ctx" | |
# } | |
# contains `pull` refs which GitHub refuses to accept, needs to wait for refs whitelist/blacklist feature | |
# - | | |
# { | |
# "name": "libre-menu-editor" | |
# } | |
- | | |
{ | |
"name": "blackbox" | |
} | |
name: "πͺ Mirror `${{ fromJSON(matrix['json'])['name'] }}`" | |
environment: | |
name: "${{ format('mirror--{0}', fromJSON(matrix['json'])['name']) }}" | |
url: > | |
${{ format('https://github.com/{0}/{1}', | |
github.repository_owner, | |
fromJSON(matrix['json'])['name'] | |
)}} | |
runs-on: 'ubuntu-latest' | |
steps: | |
- name: "Verify Remote Git Refs Equality" | |
id: 'verify-refs' | |
uses: 'actions-rindeal/git-remote-ref-compare@master' | |
with: | |
'source-repo-url': ${{ vars['SOURCE_REPO_URL'] }} | |
# TODO: refactor the repo/url processing from the action's index.js into a separate step and then use its outputs here and in the mirroring action | |
'target-repo-url': https://github.com/facsimiles/${{ vars['TARGET_GITHUB_REPO'] || fromJSON(matrix['json'])['name'] }}.git | |
env: | |
'RUNNER_DEBUG': '1' | |
- name: "π₯ Checkout ${{ github.repository }}" | |
if: ${{ steps['verify-refs'].outputs['refs-differ'] == 'true' }} | |
uses: 'actions/checkout@main' | |
- name: "π Create GitHub App Token" | |
if: ${{ steps['verify-refs'].outputs['refs-differ'] == 'true' }} | |
uses: 'actions/create-github-app-token@v1' | |
id: 'app-token' | |
with: | |
'app-id': ${{ vars['PUSH_APP_ID'] }} | |
'private-key': ${{ secrets['PUSH_APP_PRIVATE_KEY'] }} | |
'owner': ${{ github.repository_owner }} | |
'repositories': "${{ fromJSON(matrix['json'])['name'] }}" | |
- name: "π Set GitHub App/Bot π€ as Git User π€" | |
if: ${{ steps['verify-refs'].outputs['refs-differ'] == 'true' }} | |
uses: 'actions-rindeal/git-identity-from-username@v2' | |
with: | |
'username': ${{ format('{0}[bot]', steps['app-token'].outputs['app-slug']) }} | |
'failover-name': 'facsimiles-push[bot]' | |
'failover-email': '180179525+facsimiles-push[bot]@users.noreply.github.com' | |
- name: "π Mirror Repository" | |
if: ${{ steps['verify-refs'].outputs['refs-differ'] == 'true' }} | |
id: 'mirror' | |
uses: './.github/actions/git-mirror' | |
with: | |
'source-repo-url': ${{ vars['SOURCE_REPO_URL'] }} | |
'target-github-repo': ${{ vars['TARGET_GITHUB_REPO'] || fromJSON(matrix['json'])['name'] }} | |
'target-ssh-key': ${{ secrets['TARGET_SSH_KEY'] }} | |
'target-token': ${{ secrets['TARGET_TOKEN'] || steps['app-token'].outputs['token'] }} | |
- name: "π Log Mirroring Step Metadata" | |
if: ${{ steps['verify-refs'].outputs['refs-differ'] == 'true' && always() }} | |
shell: bash | |
run: | | |
echo "${MIRROR_STEP_JSON}" | jq -C . | |
env: | |
MIRROR_STEP_JSON: ${{ toJSON(steps['mirror']) }} |