From 7e517fc7d731c16127a2fb13ec71ba00a55643cf Mon Sep 17 00:00:00 2001 From: Paulo Vareiro Date: Fri, 9 Aug 2024 12:24:54 +0100 Subject: [PATCH 1/7] feat: deploy to github pages --- .github/workflows/deploy-to-github-pages.yml | 98 ++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 .github/workflows/deploy-to-github-pages.yml diff --git a/.github/workflows/deploy-to-github-pages.yml b/.github/workflows/deploy-to-github-pages.yml new file mode 100644 index 0000000..89783c7 --- /dev/null +++ b/.github/workflows/deploy-to-github-pages.yml @@ -0,0 +1,98 @@ +name: Deploy to GitHub Pages + +on: + push: + branches: ['main'] + pull_request: + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: 'pages' + cancel-in-progress: false + +jobs: + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + + - uses: pnpm/action-setup@v2 + name: Install pnpm + id: pnpm-install + with: + version: 8.6.2 + run_install: false + + - name: Install dependencies + run: pnpm i + + - name: Build + run: pnpm build + + - name: Prepare deployment directory + run: | + BRANCH_NAME=$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}} | tr '/' '_') + mkdir -p deployment/archives + mkdir -p deployment/${BRANCH_NAME} + cp -r dist/* deployment/${BRANCH_NAME}/ + + - name: Create archive + run: | + BRANCH_NAME=$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}} | tr '/' '_') + mkdir -p deployment/archives + tar -czf deployment/archives/${BRANCH_NAME}.tar -C deployment/${BRANCH_NAME} . + + - name: Download and unpack existing archives + run: | + BRANCH_NAME=$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}} | tr '/' '_') + mkdir -p deployment/archives + git fetch --all + for branch in $(git branch -r | grep -v '\->' | sed 's/origin\///'); do + safe_branch=$(echo ${branch} | tr '/' '_') + if [ "${safe_branch}" != "${BRANCH_NAME}" ]; then + echo "Checking for existing archive for branch: ${branch}" + if curl --head --fail -s https://virtualidentityag.github.io/stadtKoeln-openData-frontend/archives/${safe_branch}.tar; then + echo "Downloading archive for branch: ${branch}" + curl -L -o deployment/archives/${safe_branch}.tar https://virtualidentityag.github.io/stadtKoeln-openData-frontend/archives/${safe_branch}.tar + mkdir -p deployment/${safe_branch} + tar -xzf deployment/archives/${safe_branch}.tar -C deployment/${safe_branch} + else + echo "Branch ${branch} was not deployed to GitHub Pages" + fi + fi + done + + - name: Generate index file + run: | + echo "

Deployed Branches

" >> deployment/index.html + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + # Upload the deployment directory + path: 'deployment' + + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 From 838f67addfd9bcd52e3f7aeea13167a1e5559e45 Mon Sep 17 00:00:00 2001 From: Paulo Vareiro Date: Fri, 9 Aug 2024 14:02:59 +0100 Subject: [PATCH 2/7] fix: relative asset paths --- vite.config.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vite.config.js b/vite.config.js index f69b659..33cf377 100644 --- a/vite.config.js +++ b/vite.config.js @@ -14,4 +14,9 @@ export default { }, }), ], + experimental: { + renderBuiltUrl(filename) { + return `./${filename}` + }, + }, } From 446e05e930c6f5a2acfa5f475fa704e7cc2ded01 Mon Sep 17 00:00:00 2001 From: Paulo Vareiro Date: Fri, 9 Aug 2024 15:08:40 +0100 Subject: [PATCH 3/7] chore: add bootstrap from cdn to deployment index file (wip) --- .github/workflows/deploy-to-github-pages.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-to-github-pages.yml b/.github/workflows/deploy-to-github-pages.yml index 89783c7..7ddc316 100644 --- a/.github/workflows/deploy-to-github-pages.yml +++ b/.github/workflows/deploy-to-github-pages.yml @@ -80,7 +80,11 @@ jobs: - name: Generate index file run: | - echo "

Deployed Branches

    " > deployment/index.html + echo " + + + +

    Deployed Branches

      " > deployment/index.html for archive in deployment/archives/*.tar; do branch_name=$(basename $archive .tar) echo "
    • ${branch_name}
    • " >> deployment/index.html From 0d2d368f1f986525733fbed6988e310c76a98dd9 Mon Sep 17 00:00:00 2001 From: Paulo Vareiro Date: Fri, 9 Aug 2024 15:46:47 +0100 Subject: [PATCH 4/7] feat: implement build preview with latest styles (wip) --- .github/workflows/deploy-to-github-pages.yml | 17 ++++++------- scripts/build-preview.js | 26 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 scripts/build-preview.js diff --git a/.github/workflows/deploy-to-github-pages.yml b/.github/workflows/deploy-to-github-pages.yml index 7ddc316..65eb1ae 100644 --- a/.github/workflows/deploy-to-github-pages.yml +++ b/.github/workflows/deploy-to-github-pages.yml @@ -80,16 +80,13 @@ jobs: - name: Generate index file run: | - echo " - - - -

      Deployed Branches

        " > deployment/index.html - for archive in deployment/archives/*.tar; do - branch_name=$(basename $archive .tar) - echo "
      • ${branch_name}
      • " >> deployment/index.html - done - echo "
      " >> deployment/index.html + branches=$(ls deployment/archives/*.tar | xargs -n 1 basename | sed 's/.tar//') + echo "branches=$branches" >> $GITHUB_ENV + node scripts/build-preview.js $branches > deployment/index.html + cp deployment/index.html src/pages/preview.twig + pnpm build + rm deployment/index.html + mv dist/preview.html deployment/index.html - name: Upload artifact uses: actions/upload-pages-artifact@v3 diff --git a/scripts/build-preview.js b/scripts/build-preview.js new file mode 100644 index 0000000..b909d55 --- /dev/null +++ b/scripts/build-preview.js @@ -0,0 +1,26 @@ +const processBranches = (branches) => + branches + .map((branch) => `
    • ${branch}
    • `) + .join('') + +const main = () => { + const branches = process.argv.slice(2) + console.log( + ` + + + Stadt Koeln - Open Data + + + +

      Deployed Branches

      +
        + ${processBranches(branches)} +
      + + +`.trim() + ) +} + +main() From 9c8f05b2164f68a7886d761e0ef45815ba87ef8a Mon Sep 17 00:00:00 2001 From: Paulo Vareiro Date: Fri, 9 Aug 2024 15:50:11 +0100 Subject: [PATCH 5/7] fix: missing css file --- .github/workflows/deploy-to-github-pages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-to-github-pages.yml b/.github/workflows/deploy-to-github-pages.yml index 65eb1ae..d60dd8e 100644 --- a/.github/workflows/deploy-to-github-pages.yml +++ b/.github/workflows/deploy-to-github-pages.yml @@ -87,6 +87,7 @@ jobs: pnpm build rm deployment/index.html mv dist/preview.html deployment/index.html + mv dist/assets/styles*.css deployment/assets/ - name: Upload artifact uses: actions/upload-pages-artifact@v3 From d9f1752513d65bf87c55d8794d95da8fb232f5d4 Mon Sep 17 00:00:00 2001 From: Paulo Vareiro Date: Fri, 9 Aug 2024 15:53:12 +0100 Subject: [PATCH 6/7] fix: missing assets folder --- .github/workflows/deploy-to-github-pages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-to-github-pages.yml b/.github/workflows/deploy-to-github-pages.yml index d60dd8e..d5f57c5 100644 --- a/.github/workflows/deploy-to-github-pages.yml +++ b/.github/workflows/deploy-to-github-pages.yml @@ -86,6 +86,7 @@ jobs: cp deployment/index.html src/pages/preview.twig pnpm build rm deployment/index.html + mkdir -p deployment/assets mv dist/preview.html deployment/index.html mv dist/assets/styles*.css deployment/assets/ From 343691ffa433f22718561b6f8b8f0e6fbe8ed55d Mon Sep 17 00:00:00 2001 From: Paulo Vareiro Date: Fri, 9 Aug 2024 16:09:01 +0100 Subject: [PATCH 7/7] feat: remove all pages to be build for faster preview page build --- .github/workflows/deploy-to-github-pages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-to-github-pages.yml b/.github/workflows/deploy-to-github-pages.yml index d5f57c5..13e9566 100644 --- a/.github/workflows/deploy-to-github-pages.yml +++ b/.github/workflows/deploy-to-github-pages.yml @@ -83,6 +83,7 @@ jobs: branches=$(ls deployment/archives/*.tar | xargs -n 1 basename | sed 's/.tar//') echo "branches=$branches" >> $GITHUB_ENV node scripts/build-preview.js $branches > deployment/index.html + rm -rf src/pages/* cp deployment/index.html src/pages/preview.twig pnpm build rm deployment/index.html