Skip to content

refactor(cc-tcp-components)!: rework properties to avoid impossible … #848

refactor(cc-tcp-components)!: rework properties to avoid impossible …

refactor(cc-tcp-components)!: rework properties to avoid impossible … #848

Workflow file for this run

on:
pull_request:
types:
- synchronize
- opened
- closed
name: Preview
jobs:
wait_for_build:
name: 'Wait for build to succeed'
if: |
(github.event.action == 'synchronize' || github.event.action == 'opened') &&
github.event.repository.fork == false &&
!startsWith(github.event.pull_request.head.ref, 'release-please--')
runs-on: ubuntu-latest
steps:
- name: 'Wait for build to succeed'
uses: lewagon/wait-on-check-action@v1.3.1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
check-name: test
ref: ${{ github.event.pull_request.head.sha }}
allowed-conclusions: success
publish:
name: 'Publish Preview'
needs: wait_for_build
runs-on: ubuntu-latest
steps:
- name: '[Prepare] Checkout'
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: '[Prepare] Setup Node.js'
uses: actions/setup-node@v3
with:
node-version-file: 'package.json'
cache: 'npm'
- name: '[Prepare] Install dependencies'
run: npm ci
- name: '[Prepare] Check if a preview already exists'
id: check_preview
run: |
if npm run preview:get "${BRANCH}" > /dev/null 2>&1; then
echo "exists=yes" >> $GITHUB_OUTPUT
else
echo "exists=no" >> $GITHUB_OUTPUT
fi
env:
BRANCH: ${{ github.event.pull_request.head.ref }}
PREVIEWS_CELLAR_KEY_ID: ${{ secrets.PREVIEWS_CELLAR_KEY_ID }}
PREVIEWS_CELLAR_SECRET_KEY: ${{ secrets.PREVIEWS_CELLAR_SECRET_KEY }}
- name: '[Run] Build storybook'
run: npm run storybook:build
- name: '[Run] Publish preview'
run: npm run preview:publish "${BRANCH}"
env:
BRANCH: ${{ github.event.pull_request.head.ref }}
PREVIEWS_CELLAR_KEY_ID: ${{ secrets.PREVIEWS_CELLAR_KEY_ID }}
PREVIEWS_CELLAR_SECRET_KEY: ${{ secrets.PREVIEWS_CELLAR_SECRET_KEY }}
- name: '[Finalize] Add comment'
if: steps.check_preview.outputs.exists == 'no'
uses: actions/github-script@v6
env:
PREVIEW_BASE_URL: https://clever-components-preview.cellar-c2.services.clever-cloud.com
BRANCH: ${{ github.event.pull_request.head.ref }}
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `🔎 A preview has been automatically published : ${process.env.PREVIEW_BASE_URL}/${process.env.BRANCH}/index.html.\n\n_This preview will be deleted once this PR is closed._`
});
delete:
if: |
github.event.action == 'closed' &&
github.event.repository.fork == false &&
!startsWith(github.event.pull_request.head.ref, 'release-please--')
name: 'Delete Preview'
runs-on: ubuntu-latest
steps:
- name: '[Prepare] Checkout'
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: '[Prepare] Setup Node.js'
uses: actions/setup-node@v3
with:
node-version-file: 'package.json'
cache: 'npm'
- name: '[Prepare] Install dependencies'
run: npm ci
- name: '[Run] Delete preview'
run: npm run preview:delete "${BRANCH}"
env:
BRANCH: ${{ github.event.pull_request.head.ref }}
PREVIEWS_CELLAR_KEY_ID: ${{ secrets.PREVIEWS_CELLAR_KEY_ID }}
PREVIEWS_CELLAR_SECRET_KEY: ${{ secrets.PREVIEWS_CELLAR_SECRET_KEY }}
- name: '[Finalize] Add comment'
uses: actions/github-script@v6
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `🔎 The preview has been automatically deleted.`
});