Skip to content

Commit df8b4fd

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

File tree

1 file changed

+56
-16
lines changed

1 file changed

+56
-16
lines changed

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

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,48 @@ jobs:
3131
env:
3232
VERBOSE: 0
3333
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
3934
GH_TOKEN: ${{ github.token }}
4035

4136
steps:
37+
- name: is_fork
38+
id: is_fork
39+
run: |
40+
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
41+
42+
- name: should_deploy
43+
id: should_deploy
44+
run: |
45+
echo 'should_deploy=${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/release' }}' >> $GITHUB_OUTPUT
46+
47+
- name: is_release
48+
id: is_release
49+
run: |
50+
echo 'is_release=${{ github.ref == 'refs/heads/release' }}' >> $GITHUB_OUTPUT
51+
52+
- name: "DEBUG"
53+
run: |
54+
set +x
55+
56+
echo is_fork=${{ steps.is_fork.outputs.is_fork }}
57+
echo should_deploy=${{ steps.should_deploy.outputs.should_deploy }}
58+
echo is_release=${{ steps.is_release.outputs.is_release }}
59+
60+
echo 'github.event_name =' ${{ github.event_name }}
61+
echo 'github.event.pull_request.head.repo.fork =' ${{ github.event.pull_request.head.repo.fork }}
62+
echo 'github.event.pull_request.head.repo.full_name =' ${{ github.event.pull_request.head.repo.full_name }}
63+
echo 'github.event.pull_request.base.repo.full_name =' ${{ github.event.pull_request.base.repo.full_name }}
64+
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 }}
65+
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 }}
66+
echo '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)) }}
67+
echo 'github.repository =' ${{ github.repository }}
68+
echo 'github.ref =' ${{ github.ref }}
69+
4270
- name: "Checkout code"
4371
uses: actions/checkout@v4
4472
with:
4573
fetch-depth: 0 # Number of commits to fetch. 0 indicates all history for all branches and tags.
4674
fetch-tags: true # Whether to fetch tags, even if fetch-depth > 0.
47-
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
75+
ref: ${{ github.event.pull_request.head.ref || github.ref }}
4876

4977
- name: "Install system dependencies"
5078
run: |
@@ -54,33 +82,45 @@ jobs:
5482
run: |
5583
pip3 install -r requirements.txt
5684
57-
- name: "Install awscli"
85+
- name: "Rebuild datasets (fork)"
86+
if: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
5887
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
88+
./scripts/rebuild --input-dir 'data/' --output-dir 'data_output/' --no-pull
6589
6690
- name: "Rebuild, commit and push datasets"
67-
if: github.ref != 'refs/heads/release'
91+
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.ref != 'refs/heads/release' }}
6892
run: |
6993
git config --global user.email "${{ secrets.BOT_GIT_USER_EMAIL }}"
7094
git config --global user.name "${{ secrets.BOT_GIT_USER_NAME }}"
7195
7296
./scripts/rebuild --input-dir 'data/' --output-dir 'data_output/' --push --repo="${GITHUB_REPOSITORY}"
7397
7498
- name: "Rebuild, commit, push and make a release"
75-
if: github.ref == 'refs/heads/release'
99+
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.ref == 'refs/heads/release' }}
76100
run: |
77101
git config --global user.email "${{ secrets.BOT_GIT_USER_EMAIL }}"
78102
git config --global user.name "${{ secrets.BOT_GIT_USER_NAME }}"
79103
80104
./scripts/rebuild --input-dir 'data/' --output-dir 'data_output/' --release --repo="${GITHUB_REPOSITORY}"
81105
106+
- name: "Install awscli"
107+
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/release') }}
108+
run: |
109+
pushd /tmp >/dev/null
110+
curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
111+
unzip -oqq awscliv2.zip
112+
sudo ./aws/install --update
113+
popd >/dev/null
114+
aws --version
115+
82116
- name: "Deploy dataset server"
83-
if: ${{ endsWith(github.ref, '/master') || endsWith(github.ref, '/staging') || endsWith(github.ref, '/release') }}
117+
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/release') }}
118+
env:
119+
DATA_AWS_S3_BUCKET: ${{ secrets.DATA_AWS_S3_BUCKET }}
120+
DATA_AWS_CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.DATA_AWS_CLOUDFRONT_DISTRIBUTION_ID }}
121+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
122+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
123+
AWS_DEFAULT_REGION: us-east-2
84124
run: |
85125
./scripts/upload 'data_output/'
86126

0 commit comments

Comments
 (0)