Skip to content

Commit

Permalink
ci: store and update snapshots in ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeih committed Mar 9, 2023
1 parent da4a796 commit 7890837
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 34 deletions.
1 change: 1 addition & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ runs:
dotnet-version: |
6.x
7.x
- run: npm install
shell: bash
working-directory: templates
Expand Down
24 changes: 23 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,31 @@ jobs:
name: site
path: docs/_site

snapshot-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
lfs: true

- uses: ./.github/actions/build

- run: dotnet test -c Release --filter Stage=Snapshot --no-build
working-directory: test/docfx.Snapshot.Tests
env:
BUILD_SERVER: true

- uses: actions/upload-artifact@v3
if: failure()
with:
name: screenshots
path: |
test/docfx.Snapshot.Tests/**/*.received.png
test/docfx.Snapshot.Tests/**/*.diff.png
publish-docs:
if: github.ref == 'refs/heads/main'
needs: test
needs: [test, snapshot-test]
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: pr
on:
issue_comment:
types: [created]

jobs:
update-snapshot:
if: ${{ github.event.comment.body == '/update-snapshot' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
lfs: true

- run: hub pr checkout ${{ github.event.issue.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: ./.github/actions/build

- run: dotnet test -c Release --filter Stage=Snapshot --no-build
working-directory: test/docfx.Snapshot.Tests

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'test(snapshot): update snapshots for ${{ github.sha }}'
29 changes: 0 additions & 29 deletions .github/workflows/snapshot-test.yml

This file was deleted.

3 changes: 3 additions & 0 deletions test/docfx.Snapshot.Tests/ModuleInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@

namespace Microsoft.DocAsCode.Tests
{
using System;
using System.Runtime.CompilerServices;
using DiffEngine;
using VerifyTests;

public static class ModuleInitializer
{
[ModuleInitializer]
public static void Initialize()
{
BuildServerDetector.Detected = Environment.GetEnvironmentVariable("BUILD_SERVER") == "true";
VerifyDiffPlex.Initialize(VerifyTests.DiffPlex.OutputType.Compact);
}
}
Expand Down
4 changes: 0 additions & 4 deletions test/docfx.Snapshot.Tests/SamplesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ await Verifier
.AutoVerify(includeBuildServer: false);
}

// Verify screenshots only on windows
if (!OperatingSystem.IsWindows())
continue;

var bytes = await page.ScreenshotAsync(new() { FullPage = fullPage });
await Verifier
.Verify(new Target("png", new MemoryStream(bytes)))
Expand Down

0 comments on commit 7890837

Please sign in to comment.