-
-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix deployment of docs to netlify #34984
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6ac4d2e
Fix deployment of docs to netlify
tobiasdiez 9c21a23
fix command
tobiasdiez 676362e
Add separate workflow with privileges
tobiasdiez 751fb79
fix doc publish workflow
tobiasdiez 3bf6ed8
Increase performance by uploading only one single zip file
tobiasdiez 5e54493
install zip
tobiasdiez 5ef9372
use env variable in if instead of secret
tobiasdiez 1a416e3
okay, simply remove the check then
tobiasdiez c456d6a
always run publish job
tobiasdiez f936e0b
specify output dir for unzip
tobiasdiez ac16cd7
extend deploy workflow
tobiasdiez 56ee2ac
fix output reference
tobiasdiez 27b1ada
add required permissions
tobiasdiez 0a676e1
Fix commit sha
tobiasdiez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Triggers after the documentation build has finished, | ||
# taking the artifact and uploading it to netlify | ||
name: Publish documentation | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Build documentation"] | ||
types: | ||
- completed | ||
|
||
permissions: | ||
statuses: write | ||
checks: write | ||
pull-requests: write | ||
|
||
jobs: | ||
upload-docs: | ||
runs-on: ubuntu-latest | ||
if: github.event.workflow_run.conclusion == 'success' | ||
steps: | ||
- name: Get information about workflow origin | ||
uses: potiuk/get-workflow-origin@v1_5 | ||
id: source-run-info | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
sourceRunId: ${{ github.event.workflow_run.id }} | ||
|
||
# Once https://github.com/actions/download-artifact/issues/172 and/or https://github.com/actions/download-artifact/issues/60 is implemented, we can use the official download-artifact action | ||
# For now use the solution from https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow | ||
- name: Download docs | ||
uses: actions/github-script@v3.1.0 | ||
with: | ||
script: | | ||
var artifacts = await github.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: ${{github.event.workflow_run.id }}, | ||
}); | ||
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "docs" | ||
})[0]; | ||
var download = await github.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
var fs = require('fs'); | ||
fs.writeFileSync('${{github.workspace}}/docs.zip', Buffer.from(download.data)); | ||
|
||
- name: Extract docs | ||
run: unzip docs.zip -d docs && unzip docs/docs.zip -d docs/docs | ||
|
||
- name: Deploy to Netlify | ||
id: deploy-netlify | ||
uses: netlify/actions/cli@master | ||
with: | ||
args: deploy --dir=docs/docs/docs ${NETLIFY_PRODUCTION:+"--prod"} --message ${NETLIFY_MESSAGE} --alias ${NETLIFY_ALIAS} | ||
env: | ||
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | ||
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | ||
NETLIFY_PRODUCTION: ${{ github.ref == 'refs/heads/develop' }} | ||
NETLIFY_MESSAGE: ${{ steps.source-run-info.outputs.pullRequestNumber }} | ||
NETLIFY_ALIAS: deploy-preview-${{ steps.source-run-info.outputs.pullRequestNumber }} | ||
|
||
# Add deployment as status check, PR comment and annotation | ||
# we could use the nwtgck/actions-netlify action for that, except for that it is not (yet) working in workflow_run context: https://github.com/nwtgck/actions-netlify/issues/545 | ||
- name: Add/Update deployment status PR comment | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
with: | ||
number: ${{ steps.source-run-info.outputs.pullRequestNumber }} | ||
header: preview-comment | ||
recreate: true | ||
message: | | ||
[Documentation preview for this PR](${{ steps.deploy-netlify.outputs.NETLIFY_URL }}) is ready! :tada: | ||
Built with commit: ${{ steps.source-run-info.outputs.sourceHeadSha }} | ||
|
||
- name: Update deployment status PR check | ||
uses: myrotvorets/set-commit-status-action@1.1.6 | ||
if: ${{ always() }} | ||
env: | ||
DEPLOY_SUCCESS: Successfully deployed preview. | ||
DEPLOY_FAILURE: Failed to deploy preview. | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
status: ${{ job.status == 'success' && 'success' || 'failure' }} | ||
sha: ${{ github.event.workflow_run.head_sha }} | ||
context: Deploy Documentation | ||
targetUrl: ${{ steps.deploy-netlify.outputs.NETLIFY_URL }} | ||
description: ${{ job.status == 'success' && env.DEPLOY_SUCCESS || env.DEPLOY_FAILURE }} | ||
|
||
- name: Report deployment url | ||
run: | | ||
echo "::notice::The documentation has being automatically deployed to Netlify. %0A ✅ Preview: ${{ steps.deploy-netlify.outputs.NETLIFY_URL }}" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this conditionalization should not be dropped but moved into the new
doc-publish
workflow.We don't want the
doc-publish
workflow to fail on users' repos that have GH Actions enabled.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? It's not doing its intended job and a red workflow doesn't hurt anyone. Don't you think its better to be notified by the failing workflow in case the auth token is not config correctly in the main repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to have this kind of monitoring in our main repo, restrict the error to that repo only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your suggestion, but I don't plan to invest more time into what feels like an edge case. If you (or someone else) gets annoyed by the red workflow and you don't want to setup your own netlify deploy, you can simply disable this workflow in the github ui (or change the config in your default branch).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was already implemented.
Just don't cut it out.