Skip to content

Commit 362d84e

Browse files
committed
feat: Switch mirror workflow to SSH
1 parent 769d20a commit 362d84e

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

.github/workflows/mirror.yml

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# SPDX-License-Identifier: AGPL-3.0-or-later
12
name: Mirror to GitLab and Bitbucket
23

34
on:
@@ -7,41 +8,65 @@ on:
78
- 'v*'
89
workflow_dispatch:
910

11+
permissions: read-all
12+
1013
jobs:
1114
mirror-gitlab:
1215
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
1318
if: ${{ vars.GITLAB_MIRROR_ENABLED == 'true' }}
1419

1520
steps:
1621
- name: Checkout
17-
uses: actions/checkout@v4
22+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
1823
with:
1924
fetch-depth: 0
2025

26+
- name: Setup SSH
27+
uses: webfactory/ssh-agent@dc588b651fe13675774614f8e6a936a468676387 # v0.9.0
28+
with:
29+
ssh-private-key: ${{ secrets.GITLAB_SSH_KEY }}
30+
31+
- name: Add GitLab to known hosts
32+
run: |
33+
mkdir -p ~/.ssh
34+
ssh-keyscan -t ed25519 gitlab.com >> ~/.ssh/known_hosts
35+
2136
- name: Push to GitLab
2237
env:
23-
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
2438
REPO_NAME: ${{ github.event.repository.name }}
2539
run: |
26-
git remote add gitlab https://oauth2:${GITLAB_TOKEN}@gitlab.com/hyperpolymath/${REPO_NAME}.git || true
40+
git remote add gitlab git@gitlab.com:hyperpolymath/${REPO_NAME}.git || true
2741
git push gitlab HEAD:main --force || git push gitlab HEAD:master --force
2842
git push gitlab --tags --force
2943
3044
mirror-bitbucket:
3145
runs-on: ubuntu-latest
46+
permissions:
47+
contents: read
3248
if: ${{ vars.BITBUCKET_MIRROR_ENABLED == 'true' }}
3349

3450
steps:
3551
- name: Checkout
36-
uses: actions/checkout@v4
52+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
3753
with:
3854
fetch-depth: 0
3955

56+
- name: Setup SSH
57+
uses: webfactory/ssh-agent@dc588b651fe13675774614f8e6a936a468676387 # v0.9.0
58+
with:
59+
ssh-private-key: ${{ secrets.BITBUCKET_SSH_KEY }}
60+
61+
- name: Add Bitbucket to known hosts
62+
run: |
63+
mkdir -p ~/.ssh
64+
ssh-keyscan -t ed25519 bitbucket.org >> ~/.ssh/known_hosts
65+
4066
- name: Push to Bitbucket
4167
env:
42-
BITBUCKET_TOKEN: ${{ secrets.BITBUCKET_TOKEN }}
4368
REPO_NAME: ${{ github.event.repository.name }}
4469
run: |
45-
git remote add bitbucket https://x-token-auth:${BITBUCKET_TOKEN}@bitbucket.org/hyperpolymath/${REPO_NAME}.git || true
70+
git remote add bitbucket git@bitbucket.org:hyperpolymath/${REPO_NAME}.git || true
4671
git push bitbucket HEAD:main --force || git push bitbucket HEAD:master --force
4772
git push bitbucket --tags --force

0 commit comments

Comments
 (0)