diff --git a/.github/workflows/marks.yml b/.github/workflows/marks.yml new file mode 100644 index 0000000..aa54a8d --- /dev/null +++ b/.github/workflows/marks.yml @@ -0,0 +1,55 @@ +name: Marks + +# Marks in the comments of the code (Docs/Engine/Marks.md): one that stops a commit, or that nobody knows, does not +# get in. The hooks of git check the same on a machine; they can be skipped, this cannot. +# +# One workflow for every repository: the core runs it as it is, a module calls it. The kinds of marks and the command +# are those of the core, so a module is checked out into modules/ of a checkout of the core. + +on: + push: + branches: [develop, master] + pull_request: + workflow_call: + +permissions: + contents: read + +jobs: + marks: + name: Marks + if: vars.STELLAR_MIRROR != 'true' + runs-on: ubuntu-latest + env: + IS_CORE: ${{ github.event.repository.name == 'StellarEngine-Core' }} + steps: + - name: Checkout + if: env.IS_CORE == 'true' + uses: actions/checkout@v5 + + - name: Checkout the core + if: env.IS_CORE != 'true' + uses: actions/checkout@v5 + with: + repository: QuantumDevTeam/StellarEngine-Core + ref: develop + + - name: Checkout the module + if: env.IS_CORE != 'true' + uses: actions/checkout@v5 + with: + path: modules/${{ github.event.repository.name }} + + - name: Setup .NET + uses: actions/setup-dotnet@v5 + with: + global-json-file: global.json + + # A pull request into master is a release: what may lie in develop may not go there + - name: Check the marks + env: + STAGE: ${{ (github.base_ref == 'master' || github.ref == 'refs/heads/master') && 'release' || 'commit' }} + TARGET: ${{ github.event.repository.name == 'StellarEngine-Core' && '.' || format('modules/{0}', github.event.repository.name) }} + run: | + mkdir -p packages + dotnet run --project SDK/src/Stellar.Cli/Stellar.Cli.csproj -- marks check "$TARGET" --stage "$STAGE" diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index 71a86a5..c9ffa9f 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -23,10 +23,18 @@ name: Mirror # The first snapshot comes from a machine: scripts/mirror.ps1 -Push. After that this workflow is the only writer: # on a machine, mirror.ps1 without -Push shows the next snapshot, Run workflow here publishes it. +# It never starts by itself on a timer: a release of the core sends 'orchestra-release' (release.yml), or a person +# presses Run workflow. Run workflow also takes a component the mirror does not hold yet. + on: + repository_dispatch: + types: [orchestra-release] workflow_dispatch: - schedule: - - cron: '17 3 * * *' + inputs: + add: + description: 'New components, e.g. modules/Stellar.LoggingSystem (comma separated). Empty: the ones of the mirror' + required: false + default: '' permissions: contents: write @@ -62,6 +70,8 @@ jobs: shell: pwsh env: COMPONENTS_TOKEN: ${{ secrets.STELLAR_MIRROR_TOKEN || github.token }} + # Through the environment, never pasted into the script + ADD: ${{ inputs.add }} run: | if (-not (Test-Path .orchestra)) { throw 'No .orchestra here: make the first snapshot on a machine with scripts/mirror.ps1 -Push' @@ -85,6 +95,13 @@ jobs: $workspace = Join-Path $env:RUNNER_TEMP 'orchestra' $components = @((Get-Content .orchestra -Raw | ConvertFrom-Json).Components) + # New components: a repository of the organization of the mirror, at its default branch + foreach ($entry in @("$env:ADD" -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ })) { + if ($entry -cnotmatch '^(modules|tools)/([A-Za-z][A-Za-z0-9.-]*)$') { throw "Not modules/ or tools/: $entry" } + $area, $name = $Matches[1], $Matches[2] + if ($components | Where-Object { $_.Name -eq $name }) { throw "$name is in the mirror already" } + $components += [pscustomobject]@{ Name = $name; Area = $area; Repository = "https://github.com/${{ github.repository_owner }}/$name.git" } + } foreach ($component in $components) { if ("$($component.Repository)" -like 'https://github.com/*' -and ($component.Repository -replace '\.git$', '') -ne $mirrorRepository) { Set-Credentials $component.Repository $env:COMPONENTS_TOKEN @@ -108,6 +125,18 @@ jobs: "path=$workspace" >> $env:GITHUB_OUTPUT "keep=$($keep -join ',')" >> $env:GITHUB_OUTPUT + - name: Setup .NET + uses: actions/setup-dotnet@v5 + with: + global-json-file: global.json + + # The core and every component of the snapshot, as it will be pushed + - name: Check the marks + working-directory: ${{ steps.workspace.outputs.path }} + run: | + mkdir -p packages + dotnet run --project SDK/src/Stellar.Cli/Stellar.Cli.csproj -- marks check --all --stage release + - name: Snapshot and push id: snapshot shell: pwsh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index af08d79..b9a9f5e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,9 +5,9 @@ name: Release # into the tag v and a GitHub release of the core. # # The orchestra is released by the mirror: its workflow tags the snapshot with the same version and publishes the -# release the installer installs. With the secret STELLAR_DISPATCH_TOKEN (a fine-grained token allowed to run the -# Actions of the mirror) this workflow starts it at once; without it the release of the orchestra waits for the -# nightly run of the mirror, or for Run workflow there. +# release the installer installs. With the variable STELLAR_MIRROR_APP_ID and the secret STELLAR_MIRROR_APP_KEY (the app +# that writes the mirror, see mirror.yml) this workflow starts it at once; without them the release of the orchestra +# waits for Run workflow in the mirror. Merge the modules into their master before the core: a snapshot takes it. # # The mirror holds this file too, as everything of the core: it never runs there (STELLAR_MIRROR is 'true'). @@ -34,6 +34,17 @@ jobs: with: fetch-depth: 0 + - name: Setup .NET + uses: actions/setup-dotnet@v5 + with: + global-json-file: global.json + + # Nothing that a mark stops is released: a tag cannot be taken back + - name: Check the marks + run: | + mkdir -p packages + dotnet run --project SDK/src/Stellar.Cli/Stellar.Cli.csproj -- marks check --stage release + - name: Tag and publish id: release shell: pwsh @@ -77,14 +88,20 @@ jobs: if ($LASTEXITCODE -ne 0) { throw "gh release create $tag failed" } "released=true" >> $env:GITHUB_OUTPUT + # Only a release starts the mirror. Without the app here, Run workflow in the mirror does it + - name: Token of the mirror app + id: app + if: steps.release.outputs.released == 'true' && vars.STELLAR_MIRROR_APP_ID != '' + uses: actions/create-github-app-token@v3 + with: + client-id: ${{ vars.STELLAR_MIRROR_APP_ID }} + private-key: ${{ secrets.STELLAR_MIRROR_APP_KEY }} + owner: ${{ github.repository_owner }} + repositories: StellarEngine-Mono + permission-contents: write + - name: Start the mirror - if: steps.release.outputs.released == 'true' + if: steps.app.outputs.token != '' env: - GH_TOKEN: ${{ secrets.STELLAR_DISPATCH_TOKEN }} - MIRROR: ${{ vars.STELLAR_MIRROR_REPOSITORY || 'QuantumDevTeam/StellarEngine-Mono' }} - run: | - if [ -z "$GH_TOKEN" ]; then - echo "::notice::No STELLAR_DISPATCH_TOKEN: the orchestra is released by the next run of the mirror ($MIRROR)" - exit 0 - fi - gh workflow run mirror.yml --repo "$MIRROR" --ref master + GH_TOKEN: ${{ steps.app.outputs.token }} + run: gh api "repos/${{ github.repository_owner }}/StellarEngine-Mono/dispatches" -f event_type=orchestra-release diff --git a/Docs/Architecture/Runtime.md b/Docs/Architecture/Runtime.md index 2f03918..4bc17b4 100644 --- a/Docs/Architecture/Runtime.md +++ b/Docs/Architecture/Runtime.md @@ -271,7 +271,7 @@ wins: | `ModuleInitializationParallelism` | `1` | How many modules of one level start at once | | `Verbose` | `false` | The runtime tells every step on the error output | -Settings the runtime does not know stay in `RuntimeConfiguration.Settings` for the modules. +Modules find all of them in `RuntimeConfiguration.Settings`, the command line included, by names in any case. ## Exit codes diff --git a/Docs/Engine/Marks.md b/Docs/Engine/Marks.md new file mode 100644 index 0000000..38de814 --- /dev/null +++ b/Docs/Engine/Marks.md @@ -0,0 +1,47 @@ +# Marks + +- [README.md](../../README.md) + +A mark is metadata in a comment of the code: `#` and a name in angle brackets, capital letters, digits, `-` and `_`. +`MVP` as a mark in C# is a comment `// #` followed by ``. It is found in comments only, in C#, C++, shaders, +PowerShell, shell, YAML, TOML, XML, MSBuild and Markdown files. + +## Kinds + +| File | Whose | Committed | +|---|---|---| +| `Shared/Marks/marks.json` | of the engine, the same for everyone | yes | +| `config/marks.json` | of one machine; adds kinds and replaces those of the engine | never, git ignores `config/` | + +```json +{ "Marks": { "WIP": { "Level": "Release", "Description": "Not finished: it cannot be released" } } } +``` + +| Level | How far code with the mark goes | +|---|---| +| `Info` | anywhere | +| `Release` | into commits and `develop`, not into `master`, a release or the mirror | +| `Commit` | nowhere: not even into a commit | + +A mark of a kind that is in neither file is stopped everywhere: a typing error, or a kind of another machine. + +## Checking + +```powershell +stellar marks install --all # git checks every commit, merge and push of the core, the modules and the tools +stellar marks list --all # where the marks are +stellar marks check # the files of this repository +stellar marks check --staged # what the next commit changes +stellar marks check --all --stage release +stellar marks uninstall --all +``` + +| Where | What it checks | +|---|---| +| the hooks of git | what is committed, merged and pushed | +| `.github/workflows/marks.yml` | every push to `develop` and `master` and every pull request; `master` as a release. A module calls the workflow of the core, `stellar modules new` writes it. Required by the rulesets | +| `.github/workflows/release.yml` | before a release is tagged | +| `.github/workflows/mirror.yml` | the core and every component, before a snapshot | + +The hooks stop the commit when the `stellar` command is missing or older than the marks. They can be skipped with +`--no-verify`; the workflows cannot. A hook somebody else wrote is never replaced. diff --git a/Docs/Engine/Modules.md b/Docs/Engine/Modules.md index 957f2a3..c15ef83 100644 --- a/Docs/Engine/Modules.md +++ b/Docs/Engine/Modules.md @@ -20,11 +20,13 @@ stellar modules build --tests --pack |---|---| | `modules new` | Renders `Shared/Templates/Modules/