[pull] master from open-wc:master #186
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
name: Preview | |
on: pull_request | |
jobs: | |
release: | |
# Prevents changesets action from creating a PR on forks | |
if: github.repository == 'open-wc/open-wc' | |
name: Preview | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v3 | |
with: | |
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits | |
fetch-depth: 0 | |
- name: Setup Node.js 16 | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '16' | |
cache: 'yarn' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Install Dependencies | |
run: yarn --frozen-lockfile | |
- name: Get the slugified branch name | |
run: | | |
branch=$(npx slugify-cli ${GITHUB_HEAD_REF}) | |
echo ::set-output name=name::$branch | |
id: slugified_branch | |
- name: Build the preview URL from the branch name | |
run: echo ::set-output name=url::https://${{steps.slugified_branch.outputs.name}}--open-wc-org.netlify.app/ | |
id: preview | |
- name: Build Documentation Site | |
env: | |
DEPLOY_URL: ${{ steps.preview.outputs.url }} | |
CONTEXT: deploy-preview | |
run: yarn site:build | |
- name: Publish to Netlify | |
env: | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
run: yarn netlify deploy --alias=${{steps.slugified_branch.outputs.name}} --dir=_site | |
- name: Post Previews | |
uses: actions/github-script@v6 | |
env: | |
PREVIEW_URL: ${{ steps.preview.outputs.url }} | |
with: | |
script: | | |
const body = `Preview published to [${process.env.PREVIEW_URL}](${process.env.PREVIEW_URL}).`; | |
github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
}).then(({data}) => { | |
const priorComment = data.find(comment => comment.body.startsWith('Preview published to')); | |
if (priorComment) { | |
github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: priorComment.id, | |
body | |
}); | |
} else { | |
github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
body | |
}); | |
} | |
}); |