diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..501d70c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +indent_style = space +insert_final_newline=true +indent_size = 2 \ No newline at end of file diff --git a/.gitattributes b/.gitattributes index 46c2b24..df5c786 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,22 @@ -# Auto detect text files and perform LF normalization -* text eol=crlf -*.html text -*.css text -*.xml text - -*.png binary -*.zip binary -*.jpg binary +# Text files crlf +*.html text eol=crlf +*.json text eol=crlf +*.js text eol=crlf +*.lock text eol=crlf +*.md text eol=crlf +*.ps1 text eol=crlf +*.styl text eol=crlf +*.vue text eol=crlf +*.xml text eol=crlf +*.yml text eol=crlf + +# Special files +.dockerignore text eol=crlf +.prettierrc text eol=crlf +Dockerfile text eol=crlf +LICENSE text eol=crlf + +# Binary files +*.jpg binary +*.png binary +*.zip binary diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml new file mode 100644 index 0000000..3134af8 --- /dev/null +++ b/.github/workflows/default.yml @@ -0,0 +1,31 @@ +name: Deploy + +on: + push: + branches: + - '*' + - '!gh-pages' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Create a new build + run: docker build -t publisher:latest -f ./dockerfiles/Deploy.Dockerfile . + deploy: + runs-on: ubuntu-latest + needs: build + if: github.ref == 'refs/heads/master' + steps: + - name: Deploy to gh-pages branch + env: + GITHUB_PAT: ${{ secrets.GITHUB_PAT }} + PUBLISHER_NAME: ${{ secrets.PUBLISHER_NAME }} + PUBLISHER_EMAIL: ${{ secrets.PUBLISHER_EMAIL }} + run: | + docker run \ + --rm \ + -e GITHUB_PAT="$env:GITHUB_PAT" \ + -e PUBLISHER_NAME="$env:PUBLISHER_NAME" \ + -e PUBLISHER_EMAIL="$env:PUBLISHER_EMAIL" \ + publisher:latest diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 04946f7..0000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,39 +0,0 @@ -trigger: - branches: - include: - - master - -pr: none - -pool: - vmImage: "windows-latest" - -steps: - - task: PowerShell@2 - displayName: "Update archives" - inputs: - targetType: "filePath" - filePath: "./update_archives.azure.ps1" - failOnStderr: true - workingDirectory: $(Build.SourcesDirectory) - - task: NodeTool@0 - displayName: "Setup node 12.x" - inputs: - versionSpec: "12.x" - - task: PowerShell@2 - displayName: "Create Build" - inputs: - targetType: "filePath" - filePath: "./build.azure.ps1" - failOnStderr: true - workingDirectory: $(Build.SourcesDirectory) - - task: PowerShell@2 - displayName: "Push Changes" - condition: succeeded() - env: - GitHub_PAT: $(GitHub_PAT) - inputs: - targetType: "inline" - script: "git push -uqf $(GitHub_PAT) HEAD:gh-pages;" - failOnStderr: true - workingDirectory: $(Build.SourcesDirectory)/docs/.vuepress/dist diff --git a/build.azure.ps1 b/build.azure.ps1 deleted file mode 100644 index 61b94dd..0000000 --- a/build.azure.ps1 +++ /dev/null @@ -1,20 +0,0 @@ -$ErrorActionPreference = "Stop"; - -Write-Host -ForegroundColor Blue "Ensuring yarn is installed.."; -npm i -g yarn; - -Write-Host -ForegroundColor Blue "Installing dependencies.."; -yarn; - -Write-Host -ForegroundColor Blue "Creating new build.."; -yarn build; - -Write-Host -ForegroundColor Blue "Initializing git repository"; -$Remote = (git remote get-url origin); -Set-Location "./docs/.vuepress/dist"; -git init; -git config --local user.name "BotPatty"; -git config --local user.email "ci@zint.ch"; -git remote add origin $Remote; -git add .; -git commit -m "auto-deployment"; \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 4199f8c..02e9888 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: container_name: gct_generator build: context: ./ - dockerfile: Dockerfile + dockerfile: ./dockerfiles/Serve.Dockerfile network_mode: 'bridge' ports: - '8080:80' diff --git a/dockerfiles/Deploy.Dockerfile b/dockerfiles/Deploy.Dockerfile new file mode 100644 index 0000000..d36a926 --- /dev/null +++ b/dockerfiles/Deploy.Dockerfile @@ -0,0 +1,22 @@ +ARG GITHUB_PAT + +FROM mcr.microsoft.com/powershell:latest AS prebuild +WORKDIR /src +COPY . . +RUN pwsh -File ./scripts/build_archives.ps1 + +FROM node:lts-buster AS build +WORKDIR /src +COPY --from=prebuild /src . +RUN yarn +RUN yarn build + +FROM mcr.microsoft.com/powershell:latest AS final +ARG GITHUB_PAT +ENV GITHUB_PAT ${GITHUB_PAT} +WORKDIR /src +RUN apt-get update +RUN apt install -y git +COPY ./scripts/deploy.ps1 ./deploy.ps1 +COPY --from=build /src/docs/.vuepress/dist ./dist +CMD [ "pwsh", "deploy.ps1" ] diff --git a/Dockerfile b/dockerfiles/Serve.Dockerfile similarity index 61% rename from Dockerfile rename to dockerfiles/Serve.Dockerfile index 5d2b42e..2f3c530 100644 --- a/Dockerfile +++ b/dockerfiles/Serve.Dockerfile @@ -1,6 +1,11 @@ -FROM node:lts-buster AS build +FROM mcr.microsoft.com/powershell:latest AS prebuild WORKDIR /src COPY . . +RUN pwsh -File ./scripts/build_archives.ps1 + +FROM node:lts-buster AS build +WORKDIR /src +COPY --from=prebuild /src . RUN yarn RUN yarn build diff --git a/docs/.vuepress/public/files/.gitkeep b/docs/.vuepress/public/files/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docs/.vuepress/public/files/Cheat_manager_v0_3.zip b/docs/.vuepress/public/files/Cheat_manager_v0_3.zip deleted file mode 100644 index 915de84..0000000 Binary files a/docs/.vuepress/public/files/Cheat_manager_v0_3.zip and /dev/null differ diff --git a/docs/.vuepress/public/files/DolphinCodes.zip b/docs/.vuepress/public/files/DolphinCodes.zip deleted file mode 100644 index 038889c..0000000 Binary files a/docs/.vuepress/public/files/DolphinCodes.zip and /dev/null differ diff --git a/docs/.vuepress/public/files/GCMCodes.zip b/docs/.vuepress/public/files/GCMCodes.zip deleted file mode 100644 index d611bb8..0000000 Binary files a/docs/.vuepress/public/files/GCMCodes.zip and /dev/null differ diff --git a/docs/.vuepress/public/files/Nintendont.zip b/docs/.vuepress/public/files/Nintendont.zip deleted file mode 100644 index 0c1756f..0000000 Binary files a/docs/.vuepress/public/files/Nintendont.zip and /dev/null differ diff --git a/update_archives.azure.ps1 b/scripts/build_archives.ps1 similarity index 59% rename from update_archives.azure.ps1 rename to scripts/build_archives.ps1 index 2ab4dfc..423d473 100644 --- a/update_archives.azure.ps1 +++ b/scripts/build_archives.ps1 @@ -1,35 +1,16 @@ +# Stop on errors $ErrorActionPreference = "Stop"; -# Retrieve commit hash from latest archive update -Write-Host -ForegroundColor Blue "Retrieving last update commit.."; -$LastGCMUpdate = (git log -1 --pretty=format:"%H" ./docs/.vuepress/public/files/GCMCodes.zip); - -if ([string]::IsNullOrWhiteSpace($LastGCMUpdate)) { - Write-Host -ForegroundColor Red "Failed to retrieve the latest update commit"; - exit -1; -} - -Write-Host -ForegroundColor Green "Last GCM Archive Update:" $LastGCMUpdate; - -# Check whether any one of the code files chnged -Write-Host -ForegroundColor Blue "Scanning for code changes.." - -$CodeUpdates = (git diff --name-only $LastGCMUpdate HEAD -- './docs/.vuepress/public/codes/*.xml') - -if ([string]::IsNullOrWhiteSpace($CodeUpdates)) { - Write-Host -ForegroundColor Green "No code changes detected"; - exit 0; -} - -Write-Host "Changed files since last archive Update:" $CodeUpdates; +# Hide progress bars +$global:ProgressPreference = 'SilentlyContinue' # Start build -Write-Host -ForegroundColor Blue "Packing new archive..."; +Write-Host "Packing archives..."; # Setup workspace -New-Item -ItemType directory -Path "./.build"; -Copy-Item "./docs/.vuepress/public/codes/*.xml" "./.build/"; -Set-Location "./.build"; +New-Item -ItemType directory -Path "./tmp" > $null; +Copy-Item "./docs/.vuepress/public/codes/*.xml" "./tmp/"; +Set-Location "./tmp"; # Helper function to convert the XML files to the GCM txt format function XmlToGcm($source, $destination, $versionname) { @@ -70,10 +51,9 @@ XmlToGcm "GMSJ01.xml" "GMSJ01.txt" "GMSJ01"; XmlToGcm "GMSJ0A.xml" "GMSJ01 (A).txt" "GMSJ01"; # Replace zip file -Write-Host "Compressing and replacing GCM archive.."; -Compress-Archive "./*.txt" "../docs/.vuepress/public/files/GCMCodes.zip" -Force; - -Write-Host -ForegroundColor Green "GCM Archive rebuilt"; +Write-Host "Compressing GCM archive.."; +Compress-Archive "./*.txt" "../docs/.vuepress/public/files/GCMCodes.zip"; +Write-Host "GCM Archive built"; # Convert files to Dolphin format Remove-Item *.txt; @@ -84,13 +64,13 @@ XmlToIni "GMSP01.xml" "GMSP01.txt" "GMSP01"; XmlToIni "GMSJ01.xml" "GMSJ01.txt" "GMSJ01"; XmlToIni "GMSJ0A.xml" "GMSJ01 (A).txt" "GMSJ01"; -Write-Host "Compressing and replacing Dolphin archive.."; -Compress-Archive "./*.txt" "../docs/.vuepress/public/files/DolphinCodes.zip" -Force; +Write-Host "Compressing Dolphin archive.."; +Compress-Archive "./*.txt" "../docs/.vuepress/public/files/DolphinCodes.zip"; -Write-Host -ForegroundColor Green "Dolphin Archive rebuilt"; +Write-Host "Dolphin Archive built"; # Cleanup Write-Host "Cleaning up.."; Set-Location ..; -Remove-Item "./.build" -Recurse; -Write-Host -ForegroundColor Green "Done"; \ No newline at end of file +Remove-Item "./tmp" -Recurse; +Write-Host "Done"; \ No newline at end of file diff --git a/scripts/deploy.ps1 b/scripts/deploy.ps1 new file mode 100644 index 0000000..34c8bfb --- /dev/null +++ b/scripts/deploy.ps1 @@ -0,0 +1,30 @@ +# Stop on errors +$ErrorActionPreference = "Stop"; +Set-StrictMode -Version Latest + +# Hide progress bars +$global:ProgressPreference = 'SilentlyContinue'; + +Set-Location "./dist" + +# Set git email and username +Write-Host "Configuring git" +git init +git config --local user.name "$env:PUBLISHER_NAME" | Out-Null; +git config --local user.email "$env:PUBLISHER_EMAIL" | Out-Null; + +# Commit all files in the dist/ directory +Write-Host "Commiting build" +git add .; +git commit -m "auto-deployment"; + +try { + # Force push to gh-pages + Write-Host "Pushing to gh-pages branch"; + git push -uqf $env:GITHUB_PAT HEAD:gh-pages 2>&1 | Out-Null; +} +catch { + Write-Error "Push failed"; +} + +Write-Host "Finished"; \ No newline at end of file