From a913daba58e6e427884a81112d86e8c6a51fa8e5 Mon Sep 17 00:00:00 2001 From: Richard Hooper Date: Tue, 1 Oct 2024 11:14:36 +0100 Subject: [PATCH] Update publish-krewplugin.yaml --- .github/workflows/publish-krewplugin.yaml | 68 +++++++++-------------- 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/.github/workflows/publish-krewplugin.yaml b/.github/workflows/publish-krewplugin.yaml index 0fac822..279d8b0 100644 --- a/.github/workflows/publish-krewplugin.yaml +++ b/.github/workflows/publish-krewplugin.yaml @@ -3,14 +3,14 @@ name: Publish Plugin to Krew on: push: branches: - - '*' # Trigger on all branches + - '*' release: types: - published - workflow_dispatch: # Allows manual triggering of the workflow + workflow_dispatch: jobs: - windows: + publish: runs-on: windows-latest steps: @@ -20,13 +20,15 @@ jobs: with: ref: ${{ github.ref }} # Check out the branch that triggered the workflow - # Ensure we're not on the main branch - - name: Check branch - run: | - if [ "${{ github.ref_name }}" = "main" ]; then - echo "This workflow does not run on the main branch." - exit 1 - fi + # # 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 @@ -78,47 +80,29 @@ jobs: run: | (Get-Content "kubectl-KubeTidy" -Raw) -replace "`r`n", "`n" | Set-Content "kubectl-KubeTidy" - linux: - runs-on: ubuntu-latest - - steps: - # Checkout the repository - - name: Checkout code - uses: actions/checkout@v3 - with: - ref: ${{ github.ref }} # Check out the branch that triggered the workflow - - # Ensure we're not on the main branch - - name: Check branch - run: | - if [ "${{ github.ref_name }}" = "main" ]; then - echo "This workflow does not run on the main branch." - exit 1 - fi - # Create tar.gz files for Linux and Darwin - name: Create Tar Files run: | # Get the version from the previous step - $version = "${{ github.ref_name }}" + $version = "${{ github.ref_name }}" # Create output directory for the tar files $outputDir = "krewplugin" - mkdir -p $outputDir + New-Item -ItemType Directory -Path $outputDir -Force # Create platform-specific directories $linuxDir = "$outputDir/linux" $darwinDir = "$outputDir/darwin" - mkdir -p $linuxDir - mkdir -p $darwinDir + New-Item -ItemType Directory -Path $linuxDir -Force + New-Item -ItemType Directory -Path $darwinDir -Force # Move the updated script to the appropriate platform directories - cp kubectl-KubeTidy "$linuxDir/kubectl-KubeTidy" - cp kubectl-KubeTidy "$darwinDir/kubectl-KubeTidy" + Copy-Item -Path "kubectl-KubeTidy" -Destination "$linuxDir/kubectl-KubeTidy" + Copy-Item -Path "kubectl-KubeTidy" -Destination "$darwinDir/kubectl-KubeTidy" # Copy the Private folder into each platform directory - cp -r Private "$linuxDir/Private" - cp -r Private "$darwinDir/Private" + Copy-Item -Path "Private" -Destination "$linuxDir/Private" -Recurse -Force + Copy-Item -Path "Private" -Destination "$darwinDir/Private" -Recurse -Force # Create tar.gz files for Linux and Darwin using the tar command tar -czf "$outputDir/KubeTidy-linux-amd64-$version.tar.gz" -C "$linuxDir" . @@ -129,8 +113,8 @@ jobs: id: create_release uses: actions/create-release@v1 with: - tag_name: ${{ github.ref_name }} # Use the version from the output - release_name: KubeTidy Release ${{ github.ref_name }} + tag_name: ${{ github.ref_name }} # Use the version from the output + release_name: KubeTidy Release ${{ github.ref_name }} draft: false prerelease: false env: @@ -141,8 +125,8 @@ jobs: uses: actions/upload-release-asset@v1 with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ${{ github.workspace }}/krewplugin/KubeTidy-linux-amd64-${{ github.ref_name }}.tar.gz - asset_name: KubeTidy-linux-amd64-${{ github.ref_name }}.tar.gz + asset_path: ${{ github.workspace }}/krewplugin/KubeTidy-linux-amd64-${{ github.ref_name }}.tar.gz + asset_name: KubeTidy-linux-amd64-${{ github.ref_name }}.tar.gz asset_content_type: application/gzip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -152,8 +136,8 @@ jobs: uses: actions/upload-release-asset@v1 with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ${{ github.workspace }}/krewplugin/KubeTidy-darwin-amd64-${{ github.ref_name }}.tar.gz - asset_name: KubeTidy-darwin-amd64-${{ github.ref_name }}.tar.gz + asset_path: ${{ github.workspace }}/krewplugin/KubeTidy-darwin-amd64-${{ github.ref_name }}.tar.gz + asset_name: KubeTidy-darwin-amd64-${{ github.ref_name }}.tar.gz asset_content_type: application/gzip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}