From a996f9a10a83aa1a140385b4c0db90558531d463 Mon Sep 17 00:00:00 2001 From: Patrick Quist Date: Tue, 10 Jan 2023 22:14:09 +0100 Subject: [PATCH] Windows build and deploy script (#4547) --- .github/workflows/deploy-win.yml | 63 ++++++++++++++++++++++++ .github/workflows/test-win.yml | 4 +- etc/scripts/build-dist-win.ps1 | 83 ++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/deploy-win.yml create mode 100644 etc/scripts/build-dist-win.ps1 diff --git a/.github/workflows/deploy-win.yml b/.github/workflows/deploy-win.yml new file mode 100644 index 00000000000..d4008891de1 --- /dev/null +++ b/.github/workflows/deploy-win.yml @@ -0,0 +1,63 @@ +name: CE Windows Build + +on: + workflow_dispatch: + inputs: + buildnumber: + description: 'Build number' + default: '' + required: true + +jobs: + build_dist: + runs-on: windows-2019 + outputs: + release_name: ${{ steps.build_dist.outputs.release_name }} + branch: ${{ steps.build_dist.outputs.branch }} + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ github.event.inputs.buildnumber }} + - name: Use Node.js 16.x + uses: actions/setup-node@v3 + with: + node-version: 16.x + cache: npm + - name: Build distribution + id: build_dist + run: powershell -File etc/scripts/build-dist-win.ps1 + - uses: actions/upload-artifact@v3 + with: + name: dist + path: out/dist-bin + + deploy: + needs: [build_dist] + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Use Node.js 16.x + uses: actions/setup-node@v3 + with: + node-version: 16.x + cache: npm + - name: Download the built distribution + uses: actions/download-artifact@v3 + with: + name: dist + path: out/dist-bin + - name: Deploy + uses: jakejarvis/s3-sync-action@master + with: + args: --acl public-read --follow-symlinks + env: + AWS_S3_BUCKET: compiler-explorer + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + SOURCE_DIR: out/dist-bin + DEST_DIR: dist/gh/${{ needs.build_dist.outputs.branch }} diff --git a/.github/workflows/test-win.yml b/.github/workflows/test-win.yml index 99216868257..54aeac2d0a8 100644 --- a/.github/workflows/test-win.yml +++ b/.github/workflows/test-win.yml @@ -1,9 +1,9 @@ name: Compiler Explorer on Windows -on: [push] +on: [push, pull_request] jobs: - build-and-test: + test: runs-on: windows-2019 steps: diff --git a/etc/scripts/build-dist-win.ps1 b/etc/scripts/build-dist-win.ps1 new file mode 100644 index 00000000000..5ceb30eaba9 --- /dev/null +++ b/etc/scripts/build-dist-win.ps1 @@ -0,0 +1,83 @@ +Set-Location -Path $PSScriptRoot/../.. +$ROOT=Get-Location + +# Assumption here is that the current commit that's checked out is already tagged +$RELEASE_FILE_NAME = (git describe --tags) -join [Environment]::NewLine -replace "gh-" +$RELEASE_NAME = (git describe --tags) -join [Environment]::NewLine +$HASH=(git rev-parse HEAD) -join [Environment]::NewLine + +Write-Host "RELEASE_FILE_NAME: $RELEASE_FILE_NAME" +Write-Host "RELEASE_NAME: $RELEASE_NAME" +Write-Host "HASH: $HASH" + +Write-Host "GITHUB_OUTPUT: $env:GITHUB_OUTPUT" + +return + +# Clear the output +Remove-Item -Path "out" -Recurse -Force -ErrorAction Ignore +New-Item -Path . -Name "out/dist" -Force -ItemType "directory" + +Set-Location -Path "./out/dist" + +New-Item -Name "git_hash" +Set-Content -Path "git_hash" -Value "$HASH" + +New-Item -Name "release_build" +Set-Content -Path "release_build" -Value "$RELEASE_NAME" + +Copy-Item -Path "$ROOT/etc" -Destination . -Recurse +Copy-Item -Path "$ROOT/examples" -Destination . -Recurse +Copy-Item -Path "$ROOT/views" -Destination . -Recurse +Copy-Item -Path "$ROOT/types" -Destination . -Recurse +Copy-Item -Path "$ROOT/package*.json" -Destination . -Recurse + +Remove-Item -Path "$ROOT/lib/storage/data" -Force -Recurse -ErrorAction Ignore + +# Set up and build and webpack everything +Set-Location -Path $ROOT + +npm install --no-audit +npm run webpack +npm run ts-compile + +# Now install only the production dependencies in our output directory +Set-Location -Path "./out/dist" +npm install --no-audit --ignore-scripts --production + +Remove-Item -Path "node_modules/.cache" -Force -Recurse -ErrorAction Ignore +Remove-Item -Path "node_modules/monaco-editor" -Force -Recurse -ErrorAction Ignore +Remove-Item -Path "node_modules" -Include "*.ts" -Force -Recurse -ErrorAction Ignore + +# Output some magic for GH to set the branch name and release name + +$BRANCH = $GITHUB_REF -replace "refs/heads/" +Add-Content -Path $env:GITHUB_OUTPUT -Value "branch=$BRANCH" +Add-Content -Path $env:GITHUB_OUTPUT -Value "release_name=$RELEASE_NAME" + +# Run to make sure we haven't just made something that won't work +node -r esm ./app.js --version --dist + +Remove-Item -Path "$ROOT/out/dist-bin" -Force -Recurse -ErrorAction Ignore +New-Item -Path $ROOT -Name "out/dist-bin" -Force -ItemType "directory" + +# This part is different from build-dist.sh (zip instead of tarxz) +if ($IsWindows -or $ENV:OS) { + Compress-Archive -Path "./*" -DestinationPath "$ROOT/out/dist-bin/$RELEASE_FILE_NAME.zip" +} else { + $env:XZ_OPT="-1 -T 0" + tar -Jcf "$ROOT/out/dist-bin/$RELEASE_FILE_NAME.tar.xz" . +} + +New-Item -Path $ROOT -Name "out/webpack" -Force -ItemType "directory" +Push-Location -Path "$ROOT/out/webpack" +if ($IsWindows -or $ENV:OS) { + Compress-Archive -Path "static/*" -DestinationPath "$ROOT/out/dist-bin/$RELEASE_FILE_NAME.static.zip" +} else { + tar -Jcf "$ROOT/out/dist-bin/$RELEASE_FILE_NAME.static.tar.xz" --transform="s,^static/,," static/* +} +Pop-Location + +Set-Content -Path "$ROOT/out/dist-bin/$RELEASE_FILE_NAME.txt" -Value "$HASH" + +Set-Location -Path $ROOT