Skip to content

Commit

Permalink
Multiple files & versions of choice (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinyoo authored Apr 20, 2021
1 parent e03626e commit 87cb09a
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 37 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ 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

- name: Run the private action
uses: ./
with:
files: '**/*.bicep'
files: ${{ matrix.files }}
version: ${{ matrix.version }}

- name: Check the result
shell: bash
Expand Down
29 changes: 15 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# 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"
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 <no-reply@aliencube.com>"

Expand All @@ -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"]
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##
Expand All @@ -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

Expand All @@ -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'

Expand Down
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
53 changes: 53 additions & 0 deletions entrypoint.ps1
Original file line number Diff line number Diff line change
@@ -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"))"
}
18 changes: 0 additions & 18 deletions entrypoint.sh

This file was deleted.

0 comments on commit 87cb09a

Please sign in to comment.