fix: preview-web can't be run on forks #394
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: pipeline | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- "v*" | |
pull_request: | |
jobs: | |
# This job is necessary as repo secrets are not availble in jobs run | |
# in pull requests from forks, thus preview-web will fail. | |
check-permissions: | |
runs-on: ubuntu-latest | |
outputs: | |
checkout-priv: ${{ steps.checkAccess.outputs.require-result }} | |
steps: | |
- name: Get User Permission | |
id: checkAccess | |
uses: actions-cool/check-user-permission@v2 | |
with: | |
require: write | |
username: ${{ github.triggering_actor }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout using PR head if sufficent permissions | |
if: ${{ github.event_name == 'pull_request' && needs.check-permissions.outputs.checkout-priv == 'true'}} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Checkout | |
if: ${{ needs.check-permissions.outputs.checkout-priv == 'false' }} | |
uses: actions/checkout@v4 | |
- name: Use Node.js 20 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "yarn" | |
- name: Install | |
env: | |
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true" | |
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true" | |
run: yarn --immutable | |
- name: Lint | |
run: yarn lint:all | |
format: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout using PR head if sufficent permissions | |
if: ${{ github.event_name == 'pull_request' && needs.check-permissions.outputs.checkout-priv == 'true'}} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Checkout | |
if: ${{ needs.check-permissions.outputs.checkout-priv == 'false' }} | |
uses: actions/checkout@v4 | |
- name: Use Node.js 20 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "yarn" | |
- name: Install | |
env: | |
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true" | |
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true" | |
run: yarn --immutable --mode=skip-build | |
- name: Format | |
run: yarn fmt:check | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout using PR head if sufficent permissions | |
if: ${{ github.event_name == 'pull_request' && needs.check-permissions.outputs.checkout-priv == 'true'}} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Checkout | |
if: ${{ needs.check-permissions.outputs.checkout-priv == 'false' }} | |
uses: actions/checkout@v4 | |
- name: Use Node.js 20 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "yarn" | |
- name: Install | |
env: | |
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true" | |
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true" | |
run: yarn --immutable | |
- name: Test | |
run: yarn test --coverage | |
env: | |
CI: true | |
- name: Publish Coverage | |
uses: codecov/codecov-action@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
test-types: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout using PR head if sufficent permissions | |
if: ${{ github.event_name == 'pull_request' && needs.check-permissions.outputs.checkout-priv == 'true'}} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Checkout | |
if: ${{ needs.check-permissions.outputs.checkout-priv == 'false' }} | |
uses: actions/checkout@v4 | |
- name: Use Node.js 20 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "yarn" | |
- name: Install | |
env: | |
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true" | |
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true" | |
run: yarn --immutable | |
- name: Test types | |
run: yarn test:types | |
env: | |
CI: true | |
storybook: | |
needs: [check-permissions] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout using PR head | |
if: ${{ github.event_name == 'pull_request' && needs.check-permissions.outputs.checkout-priv == 'true'}} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Checkout | |
if: ${{ needs.check-permissions.outputs.checkout-priv == 'false' }} | |
uses: actions/checkout@v4 | |
- name: Use Node.js 20 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "yarn" | |
- name: Install | |
env: | |
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true" | |
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true" | |
run: yarn --immutable | |
- name: Build | |
run: yarn build:storybook | |
- name: Store storybook | |
uses: actions/upload-artifact@v4 | |
with: | |
name: storybook-static | |
retention-days: 1 | |
if-no-files-found: error | |
path: storybook-static | |
compile: | |
needs: [check-permissions] | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
max-parallel: 3 | |
matrix: | |
os: [macos-latest, ubuntu-20.04, windows-latest] | |
steps: | |
- name: Checkout using PR head if sufficent permissions | |
if: ${{ github.event_name == 'pull_request' && needs.check-permissions.outputs.checkout-priv == 'true'}} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Checkout | |
if: ${{ needs.check-permissions.outputs.checkout-priv == 'false' }} | |
uses: actions/checkout@v4 | |
- name: Use Node.js 20 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "yarn" | |
- name: Setup Python 3.9 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.9' | |
- name: Install required python deps | |
run: python3 -m pip install setuptools | |
- name: Install | |
env: | |
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true" | |
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true" | |
run: yarn --immutable | |
- name: Install build deps (Linux) | |
if: runner.os == 'Linux' | |
run: | | |
sudo apt-get update && sudo apt-get install -y libudev-dev | |
- name: Build | |
run: yarn compile:production | |
env: | |
GITHUB_PR_BUILDS_KEY: ${{ secrets.PR_BUILDS_TOKEN }} | |
- name: Store compiled source | |
uses: actions/upload-artifact@v4 | |
with: | |
name: compiled-${{ matrix.os }} | |
retention-days: 1 | |
if-no-files-found: error | |
path: build | |
build-and-test-app: | |
runs-on: ${{ matrix.os }} | |
env: | |
DISPLAY: :0 | |
strategy: | |
fail-fast: false | |
max-parallel: 3 | |
matrix: | |
os: [macos-latest, ubuntu-20.04, windows-latest] | |
needs: compile | |
steps: | |
- name: Checkout using PR head if sufficent permissions | |
if: ${{ github.event_name == 'pull_request' && needs.check-permissions.outputs.checkout-priv == 'true'}} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Checkout | |
if: ${{ needs.check-permissions.outputs.checkout-priv == 'false' }} | |
uses: actions/checkout@v4 | |
- name: Use Node.js 20 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "yarn" | |
- name: Install | |
env: | |
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true" | |
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true" | |
run: yarn --immutable | |
- name: Fetch compiled source | |
uses: actions/download-artifact@v4 | |
with: | |
name: compiled-${{ matrix.os }} | |
path: build | |
- name: Build | |
run: yarn run pack | |
- name: Upload build | |
uses: actions/upload-artifact@v4 | |
with: | |
name: app-builds-${{ matrix.os }} | |
retention-days: 15 | |
if-no-files-found: error | |
path: | | |
dist/*.snap | |
dist/*.AppImage | |
dist/*.msi | |
dist/*.dmg | |
dist/latest-mac.yml | |
dist/latest-linux.yml | |
- run: yarn playwright install --with-deps chromium chromium | |
- name: Setup xvfb (Linux) | |
if: runner.os == 'Linux' | |
run: | | |
# start xvfb in the background | |
sudo /usr/bin/Xvfb $DISPLAY -screen 0 1280x1024x24 & | |
- name: Run tests | |
run: yarn e2e:app | |
env: | |
CI: "true" | |
PWTEST_VIDEO: "true" | |
HEADFUL: "true" | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload test results | |
uses: actions/upload-artifact@v4 | |
if: ${{ failure() }} | |
with: | |
name: electron-${{ matrix.os }}-test-results | |
path: playwright-report | |
- name: Upload video recordings | |
uses: actions/upload-artifact@v4 | |
if: ${{ failure() }} | |
with: | |
name: electron-${{ matrix.os }}-recordings | |
path: e2e-recordings | |
# - name: Setup xvfb (Linux) | |
# if: runner.os == 'Linux' | |
# run: | | |
# sudo apt-get install -y xvfb libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xinput0 libxcb-xfixes0 | |
# # start xvfb in the background | |
# sudo /usr/bin/Xvfb $DISPLAY -screen 0 1280x1024x24 & | |
# - name: E2E | |
# run: yarn e2e:production | |
# - name: Upload failure artifacts | |
# if: ${{ failure() }} | |
# uses: actions/upload-artifact@v2-preview | |
# with: | |
# name: diff | |
# path: | | |
# packages/configurator/e2e/output/*.png | |
# packages/configurator/e2e/output/*.webm | |
# packages/configurator/e2e/output/trace/*.zip | |
# - name: Preview demo | |
e2e-web: | |
needs: compile | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout using PR head if sufficent permissions | |
if: ${{ github.event_name == 'pull_request' && needs.check-permissions.outputs.checkout-priv == 'true'}} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Checkout | |
if: ${{ needs.check-permissions.outputs.checkout-priv == 'false' }} | |
uses: actions/checkout@v4 | |
- name: Use Node.js 20 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "yarn" | |
- name: Install | |
env: | |
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true" | |
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1 | |
run: yarn --immutable --mode=skip-build | |
- name: Install browsers | |
run: yarn playwright install --with-deps | |
- name: Fetch compiled source | |
uses: actions/download-artifact@v4 | |
with: | |
name: compiled-ubuntu-20.04 | |
path: build | |
- name: Run tests | |
run: yarn e2e:web | |
env: | |
CI: "true" | |
PWTEST_VIDEO: "true" | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/upload-artifact@v4 | |
if: ${{ failure() }} | |
with: | |
name: video-web-linux-test-results | |
path: playwright-report | |
preview-web: | |
needs: [compile, storybook] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Fetch compiled source | |
uses: actions/download-artifact@v4 | |
with: | |
name: compiled-ubuntu-20.04 | |
path: build | |
- name: Fetch storybook build | |
uses: actions/download-artifact@v4 | |
with: | |
name: storybook-static | |
path: build/renderer/storybook | |
- name: Check if secrets are available | |
run: | | |
if [[ "x${{ secrets.MY_SECRET }}" == "xval" ]]; then | |
echo "Access to secrets" | |
else | |
echo "No access to secrets" | |
exit 1 | |
fi | |
- name: Deploy preview | |
id: cloudflare-preview | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
command: pages deploy build/renderer --project-name=buddy | |
- name: Find preview comment if present | |
uses: peter-evans/find-comment@v3 | |
id: find-preview-comment | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: 'github-actions[bot]' | |
body-includes: Buddy has been automatically deployed to Cloudflare | |
- name: Create or update preview URL comment | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
comment-id: ${{ steps.find-preview-comment.outputs.comment-id }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
EdgeTX Buddy has been automatically deployed to Cloudflare. | |
✅ Preview: ${{ steps.cloudflare-preview.outputs.deployment-url }} | |
✅ Storybook: ${{ steps.cloudflare-preview.outputs.deployment-url }}/storybook | |
edit-mode: replace | |
release-web-prod: | |
needs: [e2e-web, test, storybook] | |
runs-on: ubuntu-latest | |
if: github.event_name != 'pull_request' | |
steps: | |
- name: Fetch compiled source | |
uses: actions/download-artifact@v4 | |
with: | |
name: compiled-ubuntu-20.04 | |
path: build | |
- name: Publish | |
uses: cloudflare/pages-action@1 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
projectName: buddy | |
directory: build/renderer | |
gitHubToken: ${{ secrets.GITHUB_TOKEN }} | |
release-app: | |
needs: [build-and-test-app, test] | |
runs-on: ubuntu-latest | |
if: github.event_name != 'pull_request' | |
steps: | |
- name: Fetch binaries | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: app-builds-* | |
path: app-builds | |
merge-multiple: true | |
- name: Release latest build | |
if: startsWith(github.ref, 'refs/tags/v') != true | |
uses: marvinpinto/action-automatic-releases@4edd7a5aabb1bc62e6dc99b3302d587bf3134e20 | |
with: | |
title: "Latest Build" | |
repo_token: "${{ secrets.GITHUB_TOKEN }}" | |
files: app-builds/* | |
automatic_release_tag: "latest" | |
prerelease: true | |
- name: Release tagged build | |
if: startsWith(github.ref, 'refs/tags/v') | |
uses: marvinpinto/action-automatic-releases@4edd7a5aabb1bc62e6dc99b3302d587bf3134e20 | |
with: | |
repo_token: "${{ secrets.GITHUB_TOKEN }}" | |
files: app-builds/* | |
prerelease: false |