PSScriptModule | Bootstrap | 23612741505 | push #6
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
| name: Boostrap | |
| run-name: "${{ github.event.repository.name }} | Bootstrap | ${{ github.run_id }} | ${{ github.event_name }}" | |
| # This will run every time we create push a commit to `main`. | |
| # Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| # Reference: https://docs.github.com/en/actions/security-guides/automatic-token-authentication | |
| permissions: | |
| # Need `contents: read` to checkout the repository. | |
| # Need `contents: write` to update the step metadata. | |
| contents: write | |
| jobs: | |
| get_repo_state: | |
| name: Get repository state | |
| if: ${{ !github.event.repository.is_template }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Determine current state | |
| id: current_state | |
| run: | | |
| if [ -f ./PSScriptModule.build.ps1 ]; then | |
| echo "state=BOOTSTRAP_NEW_REPO" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Read repository description | |
| uses: actions/github-script@v8 | |
| id: repo | |
| with: | |
| script: | | |
| const repo = await github.rest.repos.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| }); | |
| core.setOutput('description', repo.data.description || ''); | |
| outputs: | |
| current_state: ${{ steps.current_state.outputs.state }} | |
| description: ${{ steps.repo.outputs.description }} | |
| bootstrap: | |
| name: Bootstrap | |
| needs: get_repo_state | |
| # We will only run this action when: | |
| # The repository isn't the template repository. | |
| if: >- | |
| ${{ !github.event.repository.is_template | |
| && needs.get_repo_state.outputs.current_state == 'BOOTSTRAP_NEW_REPO'}} | |
| runs-on: ubuntu-latest | |
| env: | |
| LABELS_JSON: | | |
| [ | |
| {"name": "breaking", "color": "ff0000", "description": "Breaking change"}, | |
| {"name": "chore", "color": "ededed", "description": "Maintenance, tooling, or housekeeping"}, | |
| {"name": "dependencies", "color": "bfd4f2", "description": "Dependency updates"}, | |
| {"name": "docs", "color": "0075ca", "description": "Documentation changes"}, | |
| {"name": "feat", "color": "0e8a16", "description": "New feature or enhancement"}, | |
| {"name": "fix", "color": "d73a4a", "description": "Bug fix"}, | |
| {"name": "ignore", "color": "ededed", "description": "Exclude this PR from the release changelog"}, | |
| {"name": "refactor", "color": "5319e7", "description": "Code refactoring without behavior change"}, | |
| {"name": "agents", "color": "e4e669", "description": "AI agent guidelines changed"}, | |
| {"name": "build", "color": "5319e7", "description": "Build script or versioning changed"}, | |
| {"name": "ci", "color": "bfdadc", "description": "CI/CD workflows or actions changed"}, | |
| {"name": "cmdlets", "color": "c5def5", "description": "Source functions changed"}, | |
| {"name": "devcontainer", "color": "006b75", "description": "Dev container changed"}, | |
| {"name": "github", "color": "6e5494", "description": "GitHub config files changed"}, | |
| {"name": "lint", "color": "f9d0c4", "description": "PSScriptAnalyzer config changed"}, | |
| {"name": "security", "color": "e36209", "description": "InjectionHunter config changed"}, | |
| {"name": "template", "color": "f9d0c4", "description": "Bootstrap template files changed"}, | |
| {"name": "tests", "color": "d876e3", "description": "Test files changed"}, | |
| {"name": "vscode", "color": "1d76db", "description": "VS Code settings changed"} | |
| ] | |
| steps: | |
| # We'll need to check out the repository so that we can edit the README. | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 # Let's get all the branches. | |
| # Renane PSScriptModule.build.ps1 to MODULE_NAME.build.ps1 | |
| - name: Rename build file to match module name | |
| run: | | |
| MODULE_NAME=${{ github.event.repository.name }} | |
| git mv PSScriptModule.build.ps1 "$MODULE_NAME.build.ps1" | |
| sed -i "s/PSScriptModule/$MODULE_NAME/g" "$MODULE_NAME.build.ps1" | |
| - name: Generate new module manifest | |
| shell: pwsh | |
| run: | | |
| # Remove existing module manifest | |
| [void] (Remove-Item "src/PSScriptModule.psd1") | |
| # Create new module manifest | |
| $Params = @{ | |
| Path = "src/${{ github.event.repository.name }}.psd1" | |
| Guid = [guid]::NewGuid().ToString() | |
| Author = "${{ github.repository_owner }}" | |
| CompanyName = "${{ github.repository_owner }}" | |
| Copyright = "(c) ${{ github.repository_owner }}. All rights reserved." | |
| RootModule = "${{ github.event.repository.name }}.psm1" | |
| Description = "${{ needs.get_repo_state.outputs.description }}" | |
| ProjectUri = "https://github.com/${{ github.repository }}" | |
| LicenseUri = "https://github.com/${{ github.repository }}/blob/main/LICENSE" | |
| ReleaseNotes = "https://github.com/${{ github.repository }}/releases" | |
| } | |
| [void] (New-ModuleManifest @Params) | |
| - name: Rename prefix file to match module name | |
| run: | | |
| MODULE_NAME=${{ github.event.repository.name }} | |
| git mv src/PSScriptModule.prefix.ps1 "src/$MODULE_NAME.prefix.ps1" | |
| - name: Rename suffix file to match module name | |
| run: | | |
| MODULE_NAME=${{ github.event.repository.name }} | |
| git mv src/PSScriptModule.suffix.ps1 "src/$MODULE_NAME.suffix.ps1" | |
| - name: Update README.md | |
| run: | | |
| OWNER=${{ github.repository_owner }} | |
| MODULE_NAME=${{ github.event.repository.name }} | |
| MODULE_DESCRIPTION="${{ needs.get_repo_state.outputs.description }}" | |
| MODULE_PATH=${{ github.repository }} | |
| rm README.md | |
| mv .github/DOCS_TEMPLATE/README_template.md README.md | |
| sed -i "s|PSScriptModule|$MODULE_NAME|g" README.md | |
| sed -i "s|{MODULE_NAME}|$MODULE_NAME|g" README.md | |
| sed -i "s|{MODULE_DESCRIPTION}|$MODULE_DESCRIPTION|g" README.md | |
| sed -i "s|{MODULE_PATH}|$MODULE_PATH|g" README.md | |
| sed -i "s|{OWNER}|$OWNER|g" README.md | |
| - name: Update SUPPORT.md | |
| run: | | |
| MODULE_NAME=${{ github.event.repository.name }} | |
| sed -i "s/PSScriptModule/$MODULE_NAME/g" .github/SUPPORT.md | |
| - name: Update SECURITY.md | |
| run: | | |
| MODULE_NAME=${{ github.event.repository.name }} | |
| sed -i "s/PSScriptModule/$MODULE_NAME/g" .github/SECURITY.md | |
| - name: Update CONTRIBUTING.md | |
| run: | | |
| MODULE_NAME=${{ github.event.repository.name }} | |
| sed -i "s/PSScriptModule/$MODULE_NAME/g" CONTRIBUTING.md | |
| - name: Update LICENSE | |
| run: | | |
| OWNER=${{ github.repository_owner }} | |
| sed -i "s/Warehouse Finds/$OWNER/g" LICENSE | |
| - name: Update CODEOWNERS | |
| run: | | |
| MODULE_NAME=${{ github.event.repository.name }} | |
| sed -i "s/PSScriptModule/$MODULE_NAME/g" .github/CODEOWNERS | |
| - name: Remove FUNDING.yml | |
| run: | | |
| rm .github/FUNDING.yml | |
| - name: Update config.yml in ISSUE_TEMPLATE | |
| run: | | |
| MODULE_PATH=${{ github.repository }} | |
| sed -i "s|WarehouseFinds/PSScriptModule|$MODULE_PATH|g" .github/ISSUE_TEMPLATE/config.yml | |
| - name: Update devcontainer.json | |
| run: | | |
| MODULE_NAME=${{ github.event.repository.name }} | |
| sed -i "s/PSScriptModule/$MODULE_NAME/g" .devcontainer/devcontainer.json | |
| - name: Update copilot-instructions.md | |
| run: | | |
| MODULE_NAME=${{ github.event.repository.name }} | |
| sed -i "s/PSScriptModule/$MODULE_NAME/g" .github/copilot-instructions.md | |
| - name: Update getting-started.md | |
| run: | | |
| rm docs/getting-started.md | |
| mv .github/DOCS_TEMPLATE/getting-started_template.md docs/getting-started.md | |
| MODULE_NAME=${{ github.event.repository.name }} | |
| MODULE_DESCRIPTION="${{ needs.get_repo_state.outputs.description }}" | |
| sed -i "s/{MODULE_NAME}/$MODULE_NAME/g" docs/getting-started.md | |
| sed -i "s/{MODULE_DESCRIPTION}/$MODULE_DESCRIPTION/g" docs/getting-started.md | |
| - name: Update integration test file | |
| run: | | |
| MODULE_NAME=${{ github.event.repository.name }} | |
| sed -i "s/PSScriptModule/$MODULE_NAME/g" tests/Integration/Module.Integration.Tests.ps1 | |
| - name: Remove this workflow file | |
| run: | | |
| rm .github/workflows/bootstrap.yml | |
| - name: Commit changes | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git add . | |
| git commit -am "chore: bootstrap repository for ${{ github.event.repository.name }}" | |
| git push | |
| - name: Create repository labels | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd #v8.0.0 | |
| with: | |
| script: | | |
| const labels = JSON.parse(process.env.LABELS_JSON); | |
| for (const label of labels) { | |
| try { | |
| await github.rest.issues.createLabel({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| name: label.name, | |
| description: label.description || '', | |
| color: label.color | |
| }); | |
| } catch (error) { | |
| // Check if the error is because the label already exists | |
| if (error.status === 422) { | |
| console.log(`Label '${label.name}' already exists. Skipping.`); | |
| } else { | |
| // Log other errors | |
| console.error(`Error creating label '${label.name}': ${error}`); | |
| } | |
| } | |
| } |