From 87cb09a19af79542c37f7e8e683cb8f97111567f Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Tue, 20 Apr 2021 18:42:56 +0900 Subject: [PATCH] Multiple files & versions of choice (#4) --- .github/workflows/main.yaml | 8 +++++- Dockerfile | 29 ++++++++++---------- README.md | 7 ++--- action.yml | 8 +++++- entrypoint.ps1 | 53 +++++++++++++++++++++++++++++++++++++ entrypoint.sh | 18 ------------- 6 files changed, 86 insertions(+), 37 deletions(-) create mode 100644 entrypoint.ps1 delete mode 100644 entrypoint.sh diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 8af0f11..35ceb5e 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -8,6 +8,11 @@ jobs: runs-on: ubuntu-latest + strategy: + matrix: + files: [ '**/*.bicep', 'sample1.bicep sample2.bicep biceps/sample3.bicep biceps/sample4.bicep' ] + version: [ 'latest', 'v0.3.255', 'v0.2.x' ] + steps: - name: Checkout the repo uses: actions/checkout@v2 @@ -15,7 +20,8 @@ jobs: - name: Run the private action uses: ./ with: - files: '**/*.bicep' + files: ${{ matrix.files }} + version: ${{ matrix.version }} - name: Check the result shell: bash diff --git a/Dockerfile b/Dockerfile index 1ab9dd3..abde4c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Based on the .NET Core self-contained runtime image to run bicep CLI -FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1-bionic +FROM mcr.microsoft.com/powershell:lts-ubuntu-18.04 WORKDIR /bicep LABEL "com.github.actions.name"="Bicep Build" @@ -7,7 +7,7 @@ LABEL "com.github.actions.description"="Build ARM templates using the bicep CLI" LABEL "com.github.actions.icon"="copy" LABEL "com.github.actions.color"="orange" -LABEL "repository"="http://github.com/aliencube/bicep-actions" +LABEL "repository"="http://github.com/aliencube/bicep-build-actions" LABEL "homepage"="http://github.com/aliencube" LABEL "maintainer"="Justin Yoo " @@ -17,20 +17,21 @@ RUN apt-get update && apt-get install -y \ curl \ && rm -rf /var/lib/apt/lists/* -# Fetch the latest Bicep CLI binary -RUN curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64 +# # Fetch the latest Bicep CLI binary +# RUN curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64 +# https://github.com/Azure/bicep/releases/download/v0.3.255/bicep-linux-x64 -# Mark it as executable -RUN chmod +x ./bicep +# # Mark it as executable +# RUN chmod +x ./bicep -# Add bicep to your PATH (requires admin) -RUN sudo mv ./bicep /usr/local/bin/bicep +# # Add bicep to your PATH (requires admin) +# RUN sudo mv ./bicep /usr/local/bin/bicep -# Verify you can now access the 'bicep' command -RUN bicep --help -# Done! +# # Verify you can now access the 'bicep' command +# RUN bicep --help +# # Done! -ADD entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh +ADD entrypoint.ps1 /entrypoint.ps1 +RUN chmod +x /entrypoint.ps1 -ENTRYPOINT ["/entrypoint.sh"] +ENTRYPOINT ["pwsh", "-File", "/entrypoint.ps1"] diff --git a/README.md b/README.md index b19b245..9b232a5 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ This is a GitHub Actions that runs the [bicep CLI](https://github.com/Azure/bice ## Inputs ## -* `files` (**Required**): one or more `.bicep` files to build, delimited by a space. It allows wildcards for recursive build. +* `files` (**Required**): one or more `.bicep` files to build, delimited by a space. eg. file1 file2 file3 ... It allows wildcards for recursive build. +* `version`: Version of the bicep CLI. It can be the exact version (eg. `v0.3.255`), wildcard (eg. `v0.3.x`) or `latest`. If omitted, `latest` is set as default. ## Example Usage ## @@ -16,7 +17,7 @@ This is a GitHub Actions that runs the [bicep CLI](https://github.com/Azure/bice steps: # Runs the bicep CLI action - individual files - name: Run Bicep build - uses: aliencube/bicep-build-actions@v0.1 + uses: aliencube/bicep-build-actions@v0.3 with: files: sample1.bicep sample2.bicep biceps/sample3.bicep biceps/sample4.bicep @@ -35,7 +36,7 @@ steps: steps: # Runs the bicep CLI action - recursive + wildcard - name: Run Bicep build - uses: aliencube/bicep-build-actions@v0.1 + uses: aliencube/bicep-build-actions@v0.3 with: files: '**/*.bicep' diff --git a/action.yml b/action.yml index f93fcf1..dd959ad 100644 --- a/action.yml +++ b/action.yml @@ -10,9 +10,15 @@ inputs: files: description: List of .bicep files to build, delimited by a space. eg) file1 file2 file3 ... required: true + version: + description: Version of the bicep CLI. It can be the exact version (eg. `v0.3.255`), wildcard (eg. `v0.3.x`) or `latest`. If omitted, `latest` is set as default. + required: false runs: using: docker image: Dockerfile args: - - ${{ inputs.files }} + - -Files + - ${{ inputs.files }} + - -Version + - ${{ inputs.version }} diff --git a/entrypoint.ps1 b/entrypoint.ps1 new file mode 100644 index 0000000..26d6850 --- /dev/null +++ b/entrypoint.ps1 @@ -0,0 +1,53 @@ +Param( + [string] + [Parameter(Mandatory=$true)] + $Files, + + [string] + [Parameter(Mandatory=$false)] + $Version = "latest" +) + +if ($Files -eq $null) { + Write-Host "Please provide at least one .bicep file" -ForegroundColor Red -BackgroundColor Yellow +} + +$items = Get-ChildItem -Path $($Files -split " ") -Recurse +if (($items -eq $null) -or ($items.Count -eq 0)) { + Write-Host "Please provide at least one .bicep file" -ForegroundColor Red -BackgroundColor Yellow + + return +} + +# Check Bicep version +$uri = "https://api.github.com/repos/Azure/bicep/releases" +$headers = @{ Accept = "application/vnd.github.v3+json" } + +$releases = Invoke-RestMethod -Method GET -Uri $uri -Headers $headers +if ($Version -eq "latest") { + $release = ($releases | Select-Object -Property tag_name | Sort-Object -Descending)[0] +} else { + $release = ($releases | Where-Object { $_.tag_name -like $Version.Replace("x", "*") } | Select-Object -Property tag_name | Sort-Object -Descending)[0] +} + +$uri = "https://github.com/Azure/bicep/releases/download/$($release.tag_name)/bicep-linux-x64" + +# Fetch the given version of Bicep CLI binary +curl -Lo bicep $uri + +# Mark it as executable +chmod +x ./bicep + +# Add bicep to your PATH (requires admin) +sudo mv ./bicep /usr/local/bin/bicep + +# Verify you can now access the 'bicep' command +bicep --help +# Done! + +# Build bicep files individually +$items | ForEach-Object { + bicep build $_.FullName + + Write-Host "$($_.FullName) -> $($_.FullName.Replace(".bicep", ".json"))" +} diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index 4621db7..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -shopt -s globstar - -set -e - -if [ "$#" -lt 1 ] -then -echo "Please provide at least one .bicep file" -exit -else -echo -e "\c" -fi - -for file in "$@" -do - bicep build $file -done