switch from azure-pipelines to github actions

This commit is contained in:
Matteias Collet 2020-06-29 03:23:45 +02:00
parent 6ca62dba6e
commit 4edec7c4b7
15 changed files with 130 additions and 105 deletions

3
.editorconfig Normal file
View file

@ -0,0 +1,3 @@
indent_style = space
insert_final_newline=true
indent_size = 2

31
.gitattributes vendored
View file

@ -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

31
.github/workflows/default.yml vendored Normal file
View file

@ -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

View file

@ -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

View file

@ -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";

View file

@ -5,7 +5,7 @@ services:
container_name: gct_generator
build:
context: ./
dockerfile: Dockerfile
dockerfile: ./dockerfiles/Serve.Dockerfile
network_mode: 'bridge'
ports:
- '8080:80'

View file

@ -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" ]

View file

@ -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

View file

View file

@ -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";
Remove-Item "./tmp" -Recurse;
Write-Host "Done";

30
scripts/deploy.ps1 Normal file
View file

@ -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";