Skip to content

Commit b59f2dd

Browse files
chore: disable bot's commit & push in forks
1 parent fca1b15 commit b59f2dd

1 file changed

Lines changed: 77 additions & 18 deletions

File tree

.github/workflows/build-and-deploy.yml

Lines changed: 77 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ env:
2323

2424
jobs:
2525
build-and-deploy-datasets:
26+
# Run only if it's not a fork
27+
if: ${{ !((github.event_name == 'pull_request') && (github.event.pull_request.head.repo.fork || ((github.event.pull_request.head.repo.full_name || github.event.pull_request.base.repo.full_name) != github.repository))) }}
28+
2629
runs-on: ubuntu-20.04
2730

2831
environment:
@@ -31,20 +34,64 @@ jobs:
3134
env:
3235
VERBOSE: 0
3336
PYTHONUNBUFFERED: 1
34-
DATA_AWS_S3_BUCKET: ${{ secrets.DATA_AWS_S3_BUCKET }}
35-
DATA_AWS_CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.DATA_AWS_CLOUDFRONT_DISTRIBUTION_ID }}
36-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
37-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
38-
AWS_DEFAULT_REGION: us-east-2
3937
GH_TOKEN: ${{ github.token }}
4038

4139
steps:
40+
- name: config
41+
id: config
42+
run: |
43+
echo 'is_fork=${{ (github.event_name == 'pull_request') && (github.event.pull_request.head.repo.fork || ((github.event.pull_request.head.repo.full_name || github.event.pull_request.base.repo.full_name) != github.repository)) }}' >> $GITHUB_OUTPUT
44+
45+
echo 'should_deploy=${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/release' }}' >> $GITHUB_OUTPUT
46+
47+
echo 'is_release=${{ github.ref == 'refs/heads/release' }}' >> $GITHUB_OUTPUT
48+
49+
- name: "DEBUG"
50+
run: |
51+
set +x
52+
53+
echo is_fork=${{ steps.config.outputs.is_fork }}
54+
echo should_deploy=${{ steps.config.outputs.should_deploy }}
55+
echo is_release=${{ steps.config.outputs.is_release }}
56+
57+
echo '\n'
58+
59+
echo 'github.ref =' ${{ github.ref }}
60+
echo 'github.event_name =' ${{ github.event_name }}
61+
echo 'github.repository =' ${{ github.repository }}
62+
63+
echo '\n'
64+
65+
echo 'github.event.pull_request.head.repo.fork =' ${{ github.event.pull_request.head.repo.fork }}
66+
echo 'github.event.pull_request.head.repo.full_name =' ${{ github.event.pull_request.head.repo.full_name }}
67+
68+
echo '\n'
69+
70+
echo 'github.event.pull_request.base.repo.fork =' ${{ github.event.pull_request.base.repo.fork }}
71+
echo 'github.event.pull_request.base.repo.full_name =' ${{ github.event.pull_request.base.repo.full_name }}
72+
73+
echo '\n'
74+
75+
echo 'github.event.pull_request.head.repo.full_name || github.event.pull_request.base.repo.full_name =' ${{ github.event.pull_request.head.repo.full_name || github.event.pull_request.base.repo.full_name }}
76+
echo '(github.event.pull_request.head.repo.full_name || github.event.pull_request.base.repo.full_name) == github.repository =' ${{ (github.event.pull_request.head.repo.full_name || github.event.pull_request.base.repo.full_name) == github.repository }}
77+
echo 'github.event_name == 'pull_request' && (github.event.pull_request.head.repo.fork || ((github.event.pull_request.head.repo.full_name || github.event.pull_request.base.repo.full_name) == github.repository)) =' ${{ github.event_name == 'pull_request' && (github.event.pull_request.head.repo.fork || ((github.event.pull_request.head.repo.full_name || github.event.pull_request.base.repo.full_name) == github.repository)) }}
78+
79+
- name: "Checkout code (fork)"
80+
if: ${{ steps.config.outputs.is_fork == 'true' }}
81+
uses: actions/checkout@v4
82+
with:
83+
fetch-depth: 0 # Number of commits to fetch. 0 indicates all history for all branches and tags.
84+
fetch-tags: true # Whether to fetch tags, even if fetch-depth > 0.
85+
ref: ${{github.event.pull_request.head.ref}}
86+
repository: ${{github.event.pull_request.head.repo.full_name}}
87+
4288
- name: "Checkout code"
89+
if: ${{ steps.config.outputs.is_fork != 'true' }}
4390
uses: actions/checkout@v4
4491
with:
4592
fetch-depth: 0 # Number of commits to fetch. 0 indicates all history for all branches and tags.
4693
fetch-tags: true # Whether to fetch tags, even if fetch-depth > 0.
47-
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
94+
ref: ${{ github.head_ref || github.ref }}
4895

4996
- name: "Install system dependencies"
5097
run: |
@@ -54,33 +101,45 @@ jobs:
54101
run: |
55102
pip3 install -r requirements.txt
56103
57-
- name: "Install awscli"
104+
- name: "Rebuild datasets (fork)"
105+
if: ${{ steps.config.outputs.is_fork == 'true' }}
58106
run: |
59-
pushd /tmp >/dev/null
60-
curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
61-
unzip -oqq awscliv2.zip
62-
sudo ./aws/install --update
63-
popd >/dev/null
64-
aws --version
107+
./scripts/rebuild --input-dir 'data/' --output-dir 'data_output/' --no-pull
65108
66-
- name: "Rebuild, commit and push datasets"
67-
if: github.ref != 'refs/heads/release'
109+
- name: "Rebuild, commit and push datasets (non-release branch)"
110+
if: ${{ steps.config.outputs.is_fork != 'true' && steps.config.outputs.is_release != 'true' }}
68111
run: |
69112
git config --global user.email "${{ secrets.BOT_GIT_USER_EMAIL }}"
70113
git config --global user.name "${{ secrets.BOT_GIT_USER_NAME }}"
71114
72115
./scripts/rebuild --input-dir 'data/' --output-dir 'data_output/' --push --repo="${GITHUB_REPOSITORY}"
73116
74-
- name: "Rebuild, commit, push and make a release"
75-
if: github.ref == 'refs/heads/release'
117+
- name: "Rebuild, commit, push and make a release (release branch)"
118+
if: ${{ steps.config.outputs.is_fork != 'true' && steps.config.outputs.is_release == 'true' }}
76119
run: |
77120
git config --global user.email "${{ secrets.BOT_GIT_USER_EMAIL }}"
78121
git config --global user.name "${{ secrets.BOT_GIT_USER_NAME }}"
79122
80123
./scripts/rebuild --input-dir 'data/' --output-dir 'data_output/' --release --repo="${GITHUB_REPOSITORY}"
81124
125+
- name: "Install awscli"
126+
if: ${{ steps.config.outputs.is_fork != 'true' && steps.config.outputs.should_deploy == 'true' }}
127+
run: |
128+
pushd /tmp >/dev/null
129+
curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
130+
unzip -oqq awscliv2.zip
131+
sudo ./aws/install --update
132+
popd >/dev/null
133+
aws --version
134+
82135
- name: "Deploy dataset server"
83-
if: ${{ endsWith(github.ref, '/master') || endsWith(github.ref, '/staging') || endsWith(github.ref, '/release') }}
136+
if: ${{ steps.config.outputs.is_fork != 'true' && steps.config.outputs.should_deploy == 'true' }}
137+
env:
138+
DATA_AWS_S3_BUCKET: ${{ secrets.DATA_AWS_S3_BUCKET }}
139+
DATA_AWS_CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.DATA_AWS_CLOUDFRONT_DISTRIBUTION_ID }}
140+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
141+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
142+
AWS_DEFAULT_REGION: us-east-2
84143
run: |
85144
./scripts/upload 'data_output/'
86145

0 commit comments

Comments
 (0)