Skip to content

PSScriptModule | Bootstrap | 21321793691 | push #1

PSScriptModule | Bootstrap | 21321793691 | push

PSScriptModule | Bootstrap | 21321793691 | push #1

Workflow file for this run

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 the current step to only run the main job when the learner is on the same step.
get_repo_state:
name: Check current 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 }}
on_start:
name: On start
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": "dependencies", "color": "ededed", "description": "Dependency updates"},
{"name": "documentation", "color": "0075ca", "description": "Improvements or additions to documentation"},
{"name": "tests", "color": "d876e3", "description": "Related to tests"},
{"name": "devcontainer", "color": "0e8a16", "description": "Related to development container"},
{"name": "vscode", "color": "1d76db", "description": "Related to Visual Studio Code settings"},
{"name": "ci-cd", "color": "bfdadc", "description": "Related to GitHub Actions CI"},
{"name": "build", "color": "5319e7", "description": "Build related changes"},
{"name": "github", "color": "6e5494", "description": "GitHub configuration changes"},
{"name": "breaking", "color": "ff0000", "description": "Breaking changes"},
{"name": "feature", "color": "0e8a16", "description": "New feature or enhancement"},
{"name": "bugfix", "color": "d73a4a", "description": "Bug fix"},
{"name": "performance", "color": "5319e7", "description": "Performance improvements"}
]
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: Update README.md
run: |
MODULE_NAME=${{ github.event.repository.name }}
MODULE_DESCRIPTION="${{ needs.get_repo_state.outputs.description }}"
MODULE_PATH=${{ github.repository }}
rm README.md
mv .github/README_template.md README.md
sed -i "s|PSScriptModule|$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
- name: Update SUPPORT.md
run: |
MODULE_NAME=${{ github.event.repository.name }}
sed -i "s/PSScriptModule/$MODULE_NAME/g" .githubSUPPORT.md
- name: Update LICENSE
run: |
OWNER=${{ github.repository_owner }}
sed -i "s/Warehouse Finds/$OWNER/g" LICENSE
- 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: 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}`);
}
}
}