Skip to content

C# Compiler

C# Compiler #74

name: Compiler
on:
push:
branches: [master]
paths: [ "src/**/*.ps1", ".github/workflows/compile-scripts.yaml" ]
pull_request:
paths: [ "src/**/*.ps1", ".github/workflows/compile-scripts.yaml" ]
jobs:
changes:
runs-on: ubuntu-latest
outputs:
compiled: ${{ steps.changes.outputs.compiled }}
src: ${{ steps.changes.outputs.src }}
src_deleted: ${{ steps.changes.outputs.src_deleted }}
steps:
- name: Checkout
uses: actions/checkout@v4
# Checks for changes in the 'compiled' and 'src' directories
# We also check for deleted files so we can cleanup the compiled directory
- name: Collect Changes for Upcoming Jobs
uses: dorny/[email protected]
id: changes
with:
list-files: shell
filters: |
compiled:
- 'compiled/**'
src:
- 'src/**/*.(ps1|psm1)'
src_deleted:
- deleted: 'src/**/*.(ps1|psm1)'
cleanup-directory:
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.src_deleted == 'true'
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
# TODO - Use a git diff to determine which files were deleted
- name: Delete Compiled versions of deleted files
id: delete_files
run: |
for file in $(find compiled -type f); do
no_prefix=${file#compiled/}
if [ ! -f "src/${no_prefix}" ]; then
echo "FOUND_DELETED=true" >> $GITHUB_OUTPUT
echo "Found deleted src file ${no_prefix}, deleting compiled version."
rm $file
fi
done
- name: Commit Changes
if: ${{ steps.delete_files.outputs.FOUND_DELETED == 'true' && github.event_name == 'push' }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore(compiled): Remove compiled versions of deleted files"
build:
uses: ./.github/workflows/build.yaml
compile-scripts:
runs-on: windows-latest
needs: [changes, build]
if: ${{ needs.changes.outputs.src == 'true' }}
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Compiler Artifact
uses: dawidd6/action-download-artifact@v6
with:
workflow: build.yaml
workflow_conclusion: success
name: Compiler
# FIXME - Running the single instance which compiles a directory is broken, need to do it one by one for now.
- name: Run Compiler
shell: pwsh
run: |
$SourceDir = "src"
$OutputDir = "compiled"
$SourceFiles = Get-ChildItem -Path $SourceDir -Recurse -Filter *.ps1
foreach ($file in $SourceFiles) {
$RelativePath = $file.DirectoryName.Substring((Get-Item $SourceDir).FullName.Length).TrimStart('\');
$SourcePath = Join-Path -Path $SourceDir -ChildPath ($RelativePath | Join-Path -ChildPath $file.Name)
$OutputPath = Join-Path -Path $OutputDir -ChildPath $RelativePath
.\Compiler.exe -i $SourcePath -o $OutputPath -vvv -f;
}
- name: Commit Changes
if: ${{ needs.changes.outputs.src == 'true' && github.event_name == 'push' }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore(compiled): Compile scripts"