-
Notifications
You must be signed in to change notification settings - Fork 17
feat : auto-generate manifest.json by CI #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a01e223
feat : create manifest generator service
teamssUTXO 510313e
feat : add generate manifest cli command
teamssUTXO faee200
feat : add CI to auto-generate manifest
teamssUTXO e504ca6
fix : french translation
teamssUTXO c2a34df
fix : change CI working directory
teamssUTXO 70c8258
fix : datetime update when file don't change
teamssUTXO 40e9f3e
test : add manifest generator service tests
teamssUTXO 428bcdc
fix : coderabbit suggestion
teamssUTXO ebc247f
fix: address review follow-ups on PR #54
r1ckstardev f24efb3
fix : jenny commit
teamssUTXO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: Generate Manifest | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| paths: | ||
| - 'Translator/translations/**/*.json' | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| manifest-generation: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| CI: true | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup .NET 10 | ||
| uses: actions/setup-dotnet@v4 | ||
| with: | ||
| dotnet-version: 10.0.x | ||
|
|
||
| - name: Build solution | ||
| run: dotnet build --configuration Release | ||
|
|
||
| - name: Generate manifest.json | ||
| run: dotnet run -- generate-manifest | ||
| working-directory: Translator | ||
|
|
||
| - name: Commit | ||
| uses: EndBug/add-and-commit@v10 | ||
| with: | ||
| default_author: github_actor | ||
| add: ./manifest.json # if the working directory is the repo root dir | ||
| message: "Update manifest.json" | ||
| commit: "" | ||
| push: true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,315 @@ | ||
| using System.Security.Cryptography; | ||
| using System.Text.Json; | ||
| using BTCPayTranslator.Models; | ||
| using BTCPayTranslator.Services; | ||
| using Microsoft.Extensions.Logging.Abstractions; | ||
| using Xunit; | ||
|
|
||
| namespace BTCPayTranslator.Tests.Services; | ||
|
|
||
| public class ManifestGeneratorTests | ||
| { | ||
| [Fact] | ||
| public async Task GenerateManifest_WritesManifest_ForValidTranslationFile() | ||
| { | ||
| var tempDir = CreateTempDirectory(); | ||
| var translationsDir = Path.Combine(tempDir, "translations"); | ||
| Directory.CreateDirectory(translationsDir); | ||
| var translationFile = Path.Combine(translationsDir, "French.json"); | ||
| var manifestPath = Path.Combine(tempDir, "manifest.json"); | ||
|
|
||
| try | ||
| { | ||
| await File.WriteAllTextAsync(translationFile, """ | ||
| { | ||
| "_maintainer": "alice|https://github.com/alice", | ||
| "hello": "bonjour" | ||
| } | ||
| """); | ||
|
|
||
| var sut = CreateSut(); | ||
| var result = await sut.GenerateManifest(translationsDir, manifestPath); | ||
|
|
||
| Assert.True(result); | ||
| Assert.True(File.Exists(manifestPath)); | ||
|
|
||
| var manifest = await ReadManifest(manifestPath); | ||
| var entry = Assert.Single(manifest.Languages); | ||
|
|
||
| Assert.Equal("fr", entry.Code); | ||
| Assert.Equal("fr-FR", entry.Bcp47); | ||
| Assert.Equal("French", entry.Name); | ||
| Assert.Equal("Français", entry.Native); | ||
| Assert.Equal("translations/French.json", entry.File); | ||
| Assert.Equal("alice|https://github.com/alice", entry.Maintainer); | ||
| Assert.Equal(ComputeSha256(translationFile), entry.Sha); | ||
| Assert.Matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$", entry.Updated); | ||
| } | ||
| finally | ||
| { | ||
| if (Directory.Exists(tempDir)) | ||
| { | ||
| Directory.Delete(tempDir, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GenerateManifest_ReturnsFalse_WhenNoTranslationFilesExist() | ||
| { | ||
| var tempDir = CreateTempDirectory(); | ||
| var manifestPath = Path.Combine(tempDir, "manifest.json"); | ||
|
|
||
| try | ||
| { | ||
| var sut = CreateSut(); | ||
|
|
||
| var result = await sut.GenerateManifest(tempDir, manifestPath); | ||
|
|
||
| Assert.False(result); | ||
| Assert.False(File.Exists(manifestPath)); | ||
| } | ||
| finally | ||
| { | ||
| if (Directory.Exists(tempDir)) | ||
| { | ||
| Directory.Delete(tempDir, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GenerateManifest_ReturnsFalse_WhenTranslationDirectoryDoesNotExist() | ||
| { | ||
| var translationsDir = Path.Combine(Path.GetTempPath(), "BTCPayTranslator.Tests", Guid.NewGuid().ToString("N")); | ||
| var manifestPath = Path.Combine(Path.GetTempPath(), "BTCPayTranslator.Tests", Guid.NewGuid().ToString("N"), "manifest.json"); | ||
| var sut = CreateSut(); | ||
|
|
||
| var result = await sut.GenerateManifest(translationsDir, manifestPath); | ||
|
|
||
| Assert.False(result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GenerateManifest_RetainsUpdated_WhenExistingShaMatches() | ||
| { | ||
| var tempDir = CreateTempDirectory(); | ||
| var translationsDir = Path.Combine(tempDir, "translations"); | ||
| Directory.CreateDirectory(translationsDir); | ||
| var translationFile = Path.Combine(translationsDir, "French.json"); | ||
| var manifestPath = Path.Combine(tempDir, "manifest.json"); | ||
|
|
||
| try | ||
| { | ||
| await File.WriteAllTextAsync(translationFile, """ | ||
| { | ||
| "_maintainer": "alice|https://github.com/alice", | ||
| "hello": "bonjour" | ||
| } | ||
| """); | ||
|
|
||
| var existingSha = ComputeSha256(translationFile); | ||
| var expectedUpdated = "2024-01-02T03:04:05Z"; | ||
| var existingManifest = new Manifest( | ||
| new List<ManifestEntry> | ||
| { | ||
| new( | ||
| Code: "fr", | ||
| Bcp47: "fr-FR", | ||
| Name: "French", | ||
| Native: "Français", | ||
| File: "translations/French.json", | ||
| Sha: existingSha, | ||
| Maintainer: "old", | ||
| Updated: expectedUpdated) | ||
| }, | ||
| Redirect: null); | ||
|
|
||
| await File.WriteAllTextAsync(manifestPath, JsonSerializer.Serialize(existingManifest)); | ||
|
|
||
| var sut = CreateSut(); | ||
| var result = await sut.GenerateManifest(translationsDir, manifestPath); | ||
|
|
||
| Assert.True(result); | ||
| var generated = await ReadManifest(manifestPath); | ||
| var entry = Assert.Single(generated.Languages); | ||
| Assert.Equal(expectedUpdated, entry.Updated); | ||
| } | ||
| finally | ||
| { | ||
| if (Directory.Exists(tempDir)) | ||
| { | ||
| Directory.Delete(tempDir, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GenerateManifest_UpdatesUpdated_WhenExistingShaDiffers() | ||
| { | ||
| var tempDir = CreateTempDirectory(); | ||
| var translationsDir = Path.Combine(tempDir, "translations"); | ||
| Directory.CreateDirectory(translationsDir); | ||
| var translationFile = Path.Combine(translationsDir, "French.json"); | ||
| var manifestPath = Path.Combine(tempDir, "manifest.json"); | ||
|
|
||
| try | ||
| { | ||
| await File.WriteAllTextAsync(translationFile, """ | ||
| { | ||
| "_maintainer": "alice|https://github.com/alice", | ||
| "hello": "bonjour" | ||
| } | ||
| """); | ||
|
|
||
| var previousUpdated = "2024-01-02T03:04:05Z"; | ||
| var existingManifest = new Manifest( | ||
| new List<ManifestEntry> | ||
| { | ||
| new( | ||
| Code: "fr", | ||
| Bcp47: "fr-FR", | ||
| Name: "French", | ||
| Native: "Français", | ||
| File: "translations/French.json", | ||
| Sha: "deadbeef", | ||
| Maintainer: "old", | ||
| Updated: previousUpdated) | ||
| }, | ||
| Redirect: null); | ||
|
|
||
| await File.WriteAllTextAsync(manifestPath, JsonSerializer.Serialize(existingManifest)); | ||
|
|
||
| var sut = CreateSut(); | ||
| var result = await sut.GenerateManifest(translationsDir, manifestPath); | ||
|
|
||
| Assert.True(result); | ||
| var generated = await ReadManifest(manifestPath); | ||
| var entry = Assert.Single(generated.Languages); | ||
|
|
||
| Assert.NotEqual(previousUpdated, entry.Updated); | ||
| Assert.Matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$", entry.Updated); | ||
| } | ||
| finally | ||
| { | ||
| if (Directory.Exists(tempDir)) | ||
| { | ||
| Directory.Delete(tempDir, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GenerateManifest_SetsMaintainerToNull_WhenFieldMissing() | ||
| { | ||
| var tempDir = CreateTempDirectory(); | ||
| var translationFile = Path.Combine(tempDir, "French.json"); | ||
| var manifestPath = Path.Combine(tempDir, "manifest.json"); | ||
|
|
||
| try | ||
| { | ||
| await File.WriteAllTextAsync(translationFile, """ | ||
| { | ||
| "hello": "bonjour" | ||
| } | ||
| """); | ||
|
|
||
| var sut = CreateSut(); | ||
| var result = await sut.GenerateManifest(tempDir, manifestPath); | ||
|
|
||
| Assert.True(result); | ||
| var manifest = await ReadManifest(manifestPath); | ||
| var entry = Assert.Single(manifest.Languages); | ||
| Assert.Null(entry.Maintainer); | ||
| } | ||
| finally | ||
| { | ||
| if (Directory.Exists(tempDir)) | ||
| { | ||
| Directory.Delete(tempDir, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GenerateManifest_ReturnsFalse_WhenLanguageNameMappingIsMissing() | ||
| { | ||
| var tempDir = CreateTempDirectory(); | ||
| var translationFile = Path.Combine(tempDir, "Klingon.json"); | ||
| var manifestPath = Path.Combine(tempDir, "manifest.json"); | ||
|
|
||
| try | ||
| { | ||
| await File.WriteAllTextAsync(translationFile, """ | ||
| { | ||
| "_maintainer": "alice|https://github.com/alice", | ||
| "hello": "nuqneH" | ||
| } | ||
| """); | ||
|
|
||
| var sut = CreateSut(); | ||
| var result = await sut.GenerateManifest(tempDir, manifestPath); | ||
|
|
||
| Assert.False(result); | ||
| } | ||
| finally | ||
| { | ||
| if (Directory.Exists(tempDir)) | ||
| { | ||
| Directory.Delete(tempDir, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GenerateManifest_ReturnsFalse_WhenTranslationFileHasInvalidJson() | ||
| { | ||
| var tempDir = CreateTempDirectory(); | ||
| var translationFile = Path.Combine(tempDir, "French.json"); | ||
| var manifestPath = Path.Combine(tempDir, "manifest.json"); | ||
|
|
||
| try | ||
| { | ||
| await File.WriteAllTextAsync(translationFile, "{\"_maintainer\":"); | ||
|
|
||
| var sut = CreateSut(); | ||
| var result = await sut.GenerateManifest(tempDir, manifestPath); | ||
|
|
||
| Assert.False(result); | ||
| } | ||
| finally | ||
| { | ||
| if (Directory.Exists(tempDir)) | ||
| { | ||
| Directory.Delete(tempDir, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static ManifestGenerator CreateSut() | ||
| { | ||
| return new ManifestGenerator(NullLogger<ManifestGenerator>.Instance); | ||
| } | ||
|
|
||
| private static async Task<Manifest> ReadManifest(string path) | ||
| { | ||
| var json = await File.ReadAllTextAsync(path); | ||
| var manifest = JsonSerializer.Deserialize<Manifest>(json); | ||
| return Assert.IsType<Manifest>(manifest); | ||
| } | ||
|
|
||
| private static string ComputeSha256(string path) | ||
| { | ||
| using var sha256 = SHA256.Create(); | ||
| using var stream = File.OpenRead(path); | ||
| var hash = sha256.ComputeHash(stream); | ||
| return Convert.ToHexString(hash).ToLowerInvariant(); | ||
| } | ||
|
|
||
| private static string CreateTempDirectory() | ||
| { | ||
| var directory = Path.Combine(Path.GetTempPath(), "BTCPayTranslator.Tests", Guid.NewGuid().ToString("N")); | ||
| Directory.CreateDirectory(directory); | ||
| return directory; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
What do GitHub’s official security hardening guidelines recommend for pinning third-party actions (tag vs full-length commit SHA)?💡 Result:
GitHub's official security hardening guidelines recommend pinning third-party actions to a full-length commit SHA as the most secure option. This is the only way to use an action as an immutable release, mitigating risks from malicious updates since it requires a SHA-1 collision to compromise. They warn against short SHAs due to ambiguity risks from forks. Pinning to a tag is acceptable only if you fully trust the creator (e.g., verified badge on Marketplace), but tags are mutable and can be moved or deleted by repository access compromise. GitHub provides repository/organization policies to enforce full-length SHA pinning.
Citations:
🏁 Script executed:
Repository: btcpayserver/btcpayserver-translator
Length of output: 547
🌐 Web query:
What is the current commit SHA for EndBug/add-and-commit v10 release on GitHub💡 Result:
The current commit SHA for the EndBug/add-and-commit v10 release (v10.0.0) on GitHub is 290ea2c423ad77ca9c62ae0f5b224379612c0321. This is confirmed as the commit tagged with v10.0.0 on March 22, 2026, which bumps the version from 9.1.4 to 10.0.0 in package.json and package-lock.json. There is also a tag "v10" pointing to the same commit. No newer v10 releases exist as of 2026-04-29.
Citations:
🏁 Script executed:
Repository: btcpayserver/btcpayserver-translator
Length of output: 201
Pin third-party GitHub Action by commit SHA to reduce supply-chain risk.
On Line 41,
EndBug/add-and-commit@v10uses a mutable tag. Pin to a full-length commit SHA per GitHub's official security hardening guidelines, which recommend this as the only way to use an action as an immutable release.Proposed fix
🤖 Prompt for AI Agents