File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33on :
44 push :
55 branches : [ main ]
6- pull_request :
6+ pull_request_target :
77 branches : [ main ]
88 workflow_dispatch :
99
2020 outputs :
2121 backend_image : ${{ steps.tags.outputs.backend }}
2222 frontend_image : ${{ steps.tags.outputs.frontend }}
23+ # Only run on PRs originating from this repo to avoid exposing secrets to forks
24+ if : ${{ github.event_name != 'pull_request_target' || github.event.pull_request.head.repo.full_name == github.repository }}
2325 steps :
26+ - name : Select ref
27+ run : |
28+ if [ "${{ github.event_name }}" = "pull_request_target" ]; then
29+ echo "REF=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
30+ else
31+ echo "REF=${GITHUB_SHA}" >> $GITHUB_ENV
32+ fi
2433 - uses : actions/checkout@v4
34+ with :
35+ ref : ${{ env.REF }}
2536
2637 - name : Derive lowercase image repo
2738 run : |
@@ -73,10 +84,22 @@ jobs:
7384 deploy-compose :
7485 runs-on : ubuntu-latest
7586 needs : build-and-push
76- if : ${{ secrets.SSH_HOST != '' && secrets.SSH_USER != '' && secrets.SSH_PRIVATE_KEY != '' }}
87+ if : ${{ secrets.SSH_HOST != '' && secrets.SSH_USER != '' && secrets.SSH_PRIVATE_KEY != '' && (github.event_name != 'pull_request_target' || github.event.pull_request.head.repo.full_name == github.repository) }}
7788 environment : production
89+ concurrency :
90+ group : prod-deploy
91+ cancel-in-progress : false
7892 steps :
93+ - name : Select ref
94+ run : |
95+ if [ "${{ github.event_name }}" = "pull_request_target" ]; then
96+ echo "REF=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
97+ else
98+ echo "REF=${GITHUB_SHA}" >> $GITHUB_ENV
99+ fi
79100 - uses : actions/checkout@v4
101+ with :
102+ ref : ${{ env.REF }}
80103
81104 - name : Upload docker-compose file
82105 uses : appleboy/scp-action@v0.1.7
You can’t perform that action at this time.
0 commit comments