Skip to content

Commit bfd5a2a

Browse files
ci: Restrict deployments of environments to PR merges (#1960)
* Split the docs workflow into a build and deploy jobs, where the deploy job requires the build job to succeed. This avoids unnecessary deployments by only having the github-pages environment exist in the deploy job. * Constrain the deployment of environments to PR merges by requiring push events on master to trigger the deploy job. Co-authored-by: Giordon Stark <kratsg@gmail.com>
1 parent 868c27d commit bfd5a2a

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

.github/workflows/docs.yml

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,13 @@ on:
77
pull_request:
88
workflow_dispatch:
99

10-
# Set permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
11-
permissions:
12-
contents: read
13-
pages: write
14-
id-token: write
15-
1610
concurrency:
1711
group: ${{ github.workflow }}-${{ github.ref }}
1812
cancel-in-progress: true
1913

2014
jobs:
21-
docs:
22-
environment:
23-
name: github-pages
24-
url: ${{ steps.deployment.outputs.page_url }}
25-
15+
build:
16+
name: Build docs
2617
runs-on: ubuntu-latest
2718

2819
steps:
@@ -88,15 +79,31 @@ jobs:
8879
# is not empty
8980
[ "$(ls -A docs/_build/html/schemas)" ]
9081
91-
- name: Setup Pages
92-
uses: actions/configure-pages@v2
93-
9482
- name: Upload artifact
9583
uses: actions/upload-pages-artifact@v1
9684
with:
9785
path: 'docs/_build/html'
9886

87+
deploy:
88+
name: Deploy docs to GitHub Pages
89+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
90+
needs: build
91+
# Set permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
92+
permissions:
93+
contents: read
94+
pages: write
95+
id-token: write
96+
97+
environment:
98+
name: github-pages
99+
url: ${{ steps.deployment.outputs.page_url }}
100+
101+
runs-on: ubuntu-latest
102+
103+
steps:
104+
- name: Setup Pages
105+
uses: actions/configure-pages@v2
106+
99107
- name: Deploy to GitHub Pages
100-
if: success() && github.event_name == 'push' && github.ref == 'refs/heads/master'
101108
id: deployment
102109
uses: actions/deploy-pages@v1

0 commit comments

Comments
 (0)