|
| 1 | +name: Pages |
1 | 2 | on: |
2 | | - push: |
3 | | - branches: |
4 | | - - master |
5 | 3 | pull_request: |
6 | 4 | branches: |
7 | 5 | - master |
| 6 | + - '[0-9]+.x.x' |
| 7 | + |
8 | 8 | permissions: |
| 9 | + actions: read |
9 | 10 | contents: read |
10 | 11 | pages: write |
11 | 12 | id-token: write |
| 13 | + |
12 | 14 | concurrency: |
13 | 15 | group: pages |
14 | 16 | cancel-in-progress: false |
15 | 17 |
|
16 | | -jobs: |
17 | | - build: |
18 | | - runs-on: ubuntu-latest |
19 | | - steps: |
20 | | - - name: Checkout code |
21 | | - uses: actions/checkout@v4 |
22 | | - - name: Set up Node.js |
23 | | - uses: actions/setup-node@v4 |
24 | | - with: |
25 | | - node-version-file: '.nvmrc' |
26 | | - cache: 'npm' |
27 | | - - name: Install dependencies |
28 | | - run: npm ci |
29 | | - - name: Build project |
30 | | - run: npm run build |
31 | | - - name: Upload artifact |
32 | | - uses: actions/upload-artifact@v4 |
33 | | - if: github.event_name == 'pull_request' |
34 | | - with: |
35 | | - name: pr-${{ github.event.pull_request.number }} |
36 | | - path: './dist' |
37 | | - retention-days: 30 |
38 | | - if-no-files-found: error |
| 18 | +env: |
| 19 | + NX_CLOUD_DISTRIBUTED_EXECUTION: 'false' |
39 | 20 |
|
40 | | - deploy: |
| 21 | +jobs: |
| 22 | + pages: |
41 | 23 | environment: |
42 | 24 | name: github-pages |
43 | 25 | url: ${{ steps.deployment.outputs.page_url }} |
44 | 26 | runs-on: ubuntu-latest |
45 | | - needs: [build] |
46 | 27 | steps: |
47 | 28 | - name: Checkout code |
48 | | - uses: actions/checkout@v4 |
| 29 | + uses: actions/checkout@v5 |
49 | 30 | with: |
50 | | - ref: master |
| 31 | + path: 'skyux-icons' |
| 32 | + token: '${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}' |
| 33 | + - name: Checkout skyux |
| 34 | + uses: actions/checkout@v5 |
| 35 | + with: |
| 36 | + repository: 'blackbaud/skyux' |
| 37 | + ref: 'main' |
| 38 | + path: 'skyux' |
| 39 | + token: '${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}' |
51 | 40 | - name: Set up Node.js |
52 | | - uses: actions/setup-node@v4 |
| 41 | + uses: actions/setup-node@v5 |
53 | 42 | with: |
54 | | - node-version-file: '.nvmrc' |
55 | | - cache: 'npm' |
| 43 | + node-version-file: 'skyux/.nvmrc' |
56 | 44 | - name: Install dependencies |
57 | 45 | run: npm ci |
| 46 | + working-directory: 'skyux-icons' |
58 | 47 | - name: Build project |
59 | 48 | run: npm run build |
60 | | - - name: Download artifact |
61 | | - uses: actions/download-artifact@v4 |
| 49 | + working-directory: 'skyux-icons' |
| 50 | + - name: Install skyux |
| 51 | + run: npm ci |
| 52 | + working-directory: 'skyux' |
| 53 | + env: |
| 54 | + CYPRESS_INSTALL_BINARY: 0 |
| 55 | + - name: Build Storybooks |
| 56 | + run: npx nx run-many -t build-storybook --projects=tag:icons-preview --no-dte |
| 57 | + working-directory: 'skyux' |
| 58 | + env: |
| 59 | + NX_CLOUD_ACCESS_TOKEN: '${{ secrets.NX_CLOUD_ACCESS_TOKEN }}' |
| 60 | + - name: Build playground |
| 61 | + run: npx nx run playground:build --no-dte && mkdir -pv dist/preview-pages |
| 62 | + working-directory: 'skyux' |
| 63 | + env: |
| 64 | + NX_CLOUD_ACCESS_TOKEN: '${{ secrets.NX_CLOUD_ACCESS_TOKEN }}' |
| 65 | + - name: Retrieve other preview sites |
| 66 | + uses: actions/download-artifact@v5 |
62 | 67 | with: |
63 | 68 | github-token: '${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}' |
64 | | - path: './dist' |
| 69 | + path: skyux/dist/preview-pages/ |
65 | 70 | pattern: 'pr-*' |
66 | 71 | repository: '${{ github.repository }}' |
| 72 | + - name: Create preview site for PR ${{ github.event.number }} |
| 73 | + run: | |
| 74 | + rm -rfv dist/preview-pages/pr-${{ github.event.number }} |
| 75 | + mkdir -pv dist/preview-pages/pr-${{ github.event.number }}/storybooks |
| 76 | + mv -v dist/apps/* dist/preview-pages/pr-${{ github.event.number }}/ |
| 77 | + mv -v dist/storybook/* dist/preview-pages/pr-${{ github.event.number }}/storybooks/ |
| 78 | + for idx in dist/preview-pages/pr-${{ github.event.number }}/*/index.html; do |
| 79 | + APP_BASE_HREF="skyux-icons/pr-${{ github.event.number }}/$(basename $(dirname $idx))" |
| 80 | + echo "Setting base href to ${APP_BASE_HREF} for $idx" |
| 81 | + sed -i'' 's~<base href="/"~<base href="/'${APP_BASE_HREF}'/"~g' $idx |
| 82 | + done |
| 83 | + working-directory: 'skyux' |
| 84 | + - name: Apply icon preview link tag |
| 85 | + run: | |
| 86 | + for idx in dist/preview-pages/pr-${{ github.event.number }}/*/index.html dist/preview-pages/pr-${{ github.event.number }}/storybooks/*/iframe.html; do |
| 87 | + echo "Adding skyux-icons.svg to $idx" |
| 88 | + sed -i'' 's~</head>~<link rel="prefetch" href="./skyux-icons.svg" class="skyux-icons-preview"></head>~' $idx |
| 89 | + cp -v ../skyux-icons/dist/assets/svg/skyux-icons.svg $(dirname $idx)/ |
| 90 | + done |
| 91 | + working-directory: 'skyux' |
| 92 | + - name: Create Stackblitz link |
| 93 | + run: | |
| 94 | + mkdir -pv ${{ runner.temp }}/stackblitz |
| 95 | + cd ${{ runner.temp }}/stackblitz |
| 96 | + node ${{ github.workspace }}/skyux-icons/scripts/create-stackblitz-link.mjs --url="https://${{ github.repository_owner }}.github.io/skyux-icons/pr-${{ github.event.number }}/playground" |
| 97 | + mkdir -pv ${{ github.workspace }}/skyux/dist/preview-pages/pr-${{ github.event.number }}/stackblitz |
| 98 | + cp -v stackblitz.html ${{ github.workspace }}/skyux/dist/preview-pages/pr-${{ github.event.number }}/stackblitz/index.html |
| 99 | + - name: Generate comment for PR ${{ github.event.number }} |
| 100 | + run: | |
| 101 | + npx nx g @skyux-sdk/e2e-schematics:pr-comment --pr=pr-${{ github.event.number }} \ |
| 102 | + --url="https://${{ github.repository_owner }}.github.io/skyux-icons" \ |
| 103 | + --repoUrl="https://github.com/${{ github.repository }}" \ |
| 104 | + --apps="$(ls dist/preview-pages/pr-${{ github.event.number }} | fgrep -v storybooks | tr '\n' ,)" \ |
| 105 | + --storybooks="$(ls dist/preview-pages/pr-${{ github.event.number }}/storybooks | tr '\n' ,)" \ |
| 106 | + --skipCompositeStorybook |
| 107 | + mv -v dist/pr_index.html dist/preview-pages/pr-${{ github.event.number }}/index.html |
| 108 | + working-directory: 'skyux' |
| 109 | + - name: Save PR ${{ github.event.number }} Preview |
| 110 | + uses: actions/upload-artifact@v4 |
| 111 | + with: |
| 112 | + name: pr-${{ github.event.number }} |
| 113 | + path: skyux/dist/preview-pages/pr-${{ github.event.number }} |
| 114 | + overwrite: 'true' |
| 115 | + retention-days: 30 |
| 116 | + if-no-files-found: error |
| 117 | + - name: Setup Pages |
| 118 | + uses: actions/configure-pages@v5 |
67 | 119 | - name: Upload artifact |
68 | 120 | uses: actions/upload-pages-artifact@v3 |
69 | 121 | with: |
70 | | - path: './dist' |
| 122 | + path: skyux/dist/preview-pages |
71 | 123 | - name: Deploy to GitHub Pages |
72 | 124 | id: deployment |
73 | 125 | uses: actions/deploy-pages@v4 |
| 126 | + - name: Comment |
| 127 | + run: | |
| 128 | + COMMENT_ID=$(gh api -H "Accept: application/vnd.github-commitcomment.raw+json" -H "X-GitHub-Api-Version: 2022-11-28" repos/${{ github.repository }}/issues/${{ github.event.number }}/comments -q 'map(select(.body | contains("Component Storybooks:"))) | .[0].id // empty') |
| 129 | + if [ -n "$COMMENT_ID" ]; then |
| 130 | + echo "Updating existing comment $COMMENT_ID" |
| 131 | + gh api --method PATCH -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" repos/${{ github.repository }}/issues/comments/${COMMENT_ID} -F body=@skyux/dist/pr_comment.md |
| 132 | + else |
| 133 | + echo "Creating a new comment" |
| 134 | + gh pr comment ${{ github.event.number }} -R ${{ github.repository }} -F skyux/dist/pr_comment.md |
| 135 | + fi |
| 136 | + env: |
| 137 | + GH_TOKEN: '${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}' |
0 commit comments