formatting #9
Workflow file for this run
This file contains 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: Publish Plugin to Krew | |
on: | |
push: | |
branches: | |
- main | |
- kubectl-plugin | |
release: | |
types: | |
- published | |
workflow_dispatch: | |
jobs: | |
publish: | |
runs-on: windows-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Get the version from KubeTidy.psd1 | |
- name: Get Version from Manifest | |
id: get_version | |
run: | | |
# Get the version from the module manifest | |
$manifest = Get-Content ./KubeTidy.psd1 -Raw | Out-String | Invoke-Expression | |
$version = $manifest.ModuleVersion | |
Write-Host "Version: $version" | |
echo "::set-output name=version::$version" # Set the version as an output variable | |
# Update the KubeTidy.psm1 file for Krew Plugin | |
- name: Update KubeTidy.psm1 for Krew Plugin | |
run: | | |
# Create a copy of KubeTidy.psm1 directly in the root | |
$sourceFile = "KubeTidy.psm1" | |
$destinationFile = "kubectl-KubeTidy" | |
Copy-Item -Path $sourceFile -Destination $destinationFile -Force | |
# Prepare the param block to be inserted | |
$paramBlock = @" | |
param ( | |
[string]`$KubeConfigPath, | |
[array]`$ExclusionList, | |
[switch]`$Force, | |
[switch]`$ListClusters, | |
[array]`$MergeConfigs, | |
[string]`$DestinationConfig, | |
[switch]`$DryRun, | |
[Alias("h")] [switch]`$Help | |
) | |
"@ | |
# Read content and update it | |
$content = Get-Content $destinationFile -Raw | |
# Move the param block out of the function and replace the content | |
$content = $content -replace 'function Invoke-KubeTidy {', "$paramBlock`nfunction Invoke-KubeTidy {" | |
# Ensure the last lines are correct | |
$content += "`n# Call the function, passing parameters manually for cross-platform compatibility" | |
$content += "`nInvoke-KubeTidy \$PSBoundParameters" | |
# Write the updated content back to the file | |
Set-Content -Path $destinationFile -Value $content | |
# Update kubectl-KubeTidy.yaml with the new version | |
- name: Update Krew Manifest with Version | |
run: | | |
# Load the YAML content | |
$yamlFilePath = "kubectl-KubeTidy.yaml" | |
$yamlContent = Get-Content -Path $yamlFilePath -Raw | |
# Update the version in the YAML | |
$updatedYamlContent = $yamlContent -replace 'version: v\d+\.\d+\.\d+', "version: ${{ steps.get_version.outputs.version }}" | |
# Write the updated YAML content back to the file | |
Set-Content -Path $yamlFilePath -Value $updatedYamlContent | |
# Create zip files for different platforms | |
- name: Create Zip Files | |
run: | | |
# Get the version from the previous step | |
$version = "${{ steps.get_version.outputs.version }}" | |
# Create output directory for the zips | |
$outputDir = "krewplugin" | |
New-Item -ItemType Directory -Path $outputDir -Force | |
# Create platform-specific directories | |
$linuxDir = "$outputDir/linux" | |
$darwinDir = "$outputDir/darwin" | |
$windowsDir = "$outputDir/windows" | |
New-Item -ItemType Directory -Path $linuxDir -Force | |
New-Item -ItemType Directory -Path $darwinDir -Force | |
New-Item -ItemType Directory -Path $windowsDir -Force | |
# Move the updated script to the appropriate platform directories | |
Copy-Item -Path "kubectl-KubeTidy" -Destination "$linuxDir/kubectl-KubeTidy" | |
Copy-Item -Path "kubectl-KubeTidy" -Destination "$darwinDir/kubectl-KubeTidy" | |
Copy-Item -Path "kubectl-KubeTidy" -Destination "$windowsDir/kubectl-KubeTidy" | |
# Copy the Private folder into each platform directory | |
Copy-Item -Path "Private" -Destination "$linuxDir/Private" -Recurse -Force | |
Copy-Item -Path "Private" -Destination "$darwinDir/Private" -Recurse -Force | |
Copy-Item -Path "Private" -Destination "$windowsDir/Private" -Recurse -Force | |
# Create tar.gz files for Linux and Darwin | |
Compress-Archive -Path "$linuxDir/*" -DestinationPath "$outputDir/kubectl-KubeTidy-linux-amd64-$version.tar.gz" | |
Compress-Archive -Path "$darwinDir/*" -DestinationPath "$outputDir/kubectl-KubeTidy-darwin-amd64-$version.tar.gz" | |
Compress-Archive -Path "$windowsDir/*" -DestinationPath "$outputDir/kubectl-KubeTidy-windows-amd64-$version.zip" | |
# Create a GitHub release and upload the zip files | |
- name: Create GitHub Release | |
id: create_release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: v${{ steps.get_version.outputs.version }} # Use the version from the output | |
release_name: Release ${{ steps.get_version.outputs.version }} | |
draft: false | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Upload the tar.gz and zip files to the GitHub release | |
- name: Upload Linux Release Asset | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ github.workspace }}/krewplugin/kubectl-KubeTidy-linux-amd64-${{ steps.get_version.outputs.version }}.tar.gz | |
asset_name: kubectl-KubeTidy-linux-amd64-${{ steps.get_version.outputs.version }}.tar.gz | |
asset_content_type: application/gzip | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload Darwin Release Asset | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ github.workspace }}/krewplugin/kubectl-KubeTidy-darwin-amd64-${{ steps.get_version.outputs.version }}.tar.gz | |
asset_name: kubectl-KubeTidy-darwin-amd64-${{ steps.get_version.outputs.version }}.tar.gz | |
asset_content_type: application/gzip | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload Windows Release Asset | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ github.workspace }}/krewplugin/kubectl-KubeTidy-windows-amd64-${{ steps.get_version.outputs.version }}.zip | |
asset_name: kubectl-KubeTidy-windows-amd64-${{ steps.get_version.outputs.version }}.zip | |
asset_content_type: application/zip | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |