|
| 1 | +name: Deploy to Open Repo |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + deploy: |
| 14 | + if: | |
| 15 | + github.event.repository.name == 'staging_open' && |
| 16 | + github.event.pusher.name != 'github-actions[bot]' |
| 17 | + name: Push built output to target repo via SSH |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout repository (no persisted credentials) |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + ref: deploy |
| 24 | + fetch-depth: 0 |
| 25 | + persist-credentials: false |
| 26 | + |
| 27 | + - name: Configure git |
| 28 | + run: | |
| 29 | + git config --global user.name "github-actions[bot]" |
| 30 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 31 | + git remote add ssh-origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com:Sllambias/staging_private |
| 32 | +
|
| 33 | + - name: Start ssh-agent and add deploy key |
| 34 | + uses: webfactory/ssh-agent@v0.9.1 |
| 35 | + with: |
| 36 | + ssh-private-key: ${{ secrets.DEPLOY }} |
| 37 | + |
| 38 | + - name: Ensure github.com is in known_hosts |
| 39 | + run: | |
| 40 | + mkdir -p ~/.ssh |
| 41 | + ssh-keyscan github.com >> ~/.ssh/known_hosts |
| 42 | + chmod 644 ~/.ssh/known_hosts |
| 43 | +
|
| 44 | + - name: Update deployment with secondary main |
| 45 | + run: | |
| 46 | + git fetch ssh-origin main |
| 47 | + git rebase -X ours ssh-origin/main |
| 48 | + git merge --squash -X theirs origin/main --allow-unrelated-histories |
| 49 | + |
| 50 | + - name: Update deployment branch with local main |
| 51 | + run: | |
| 52 | + git restore --staged README.md |
| 53 | + |
| 54 | +
|
| 55 | + - name: commit |
| 56 | + run: | |
| 57 | + git commit -m "deploy changes" |
| 58 | + |
| 59 | + - name: Sync repositories |
| 60 | + run: | |
| 61 | + echo "Pushing to SSH remote: git@github.com:Sllambias/staging_private.git -> branch main" |
| 62 | +
|
| 63 | + git remote -v |
| 64 | + echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" |
| 65 | + ssh -T -o StrictHostKeyChecking=no git@github.com || true |
| 66 | + |
| 67 | + git push |
| 68 | + git push -f -u ssh-origin HEAD:main |
0 commit comments