Running bicep in GitHub Actions
Bicep is a language that is used to simplify the writing of ARM templates. Bicep is a so called DSL (Domain Specific Language) meaning that it is a specific language for a specific domains in this case ARM. The last couple of months I have written two more posts about bicep:
As mention in the second post Microsoft released bicep version 0.3.1. With this version the bicep language is not experimental any more. Some pointer about this version are:
- Parity with ARM Templates
- Integration with Azure CLI (v2.20.0+) and Azure PowerShell (v5.6.0+)
- De-compiler
- Supported by Microsoft
The second post covers how bicep can be used within Azure DevOps Pipelines. From this post I also got some question to write down the same for GitHub Actions.
Support
At the time of writing this post there GitHub Actions also supports the Azure CLI option of running bicep. But for having a faster process the outline of this post will download and install the latest version of bicep.
Running bicep in GitHub Actions
So how do we run bicep then within GitHub Actions ? To get started the tooling needs to be installed on the agent. This brings us to the first task for the pipeline that will perform the install. To install bicep the following bash code is used.
curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64 chmod +x ./bicep sudo mv ./bicep /usr/local/bin/bicep bicep --help
The script it self needs to be performed on a Linux machine to install the bicep tooling and configure bicep into the PATH variable. Doing this in GitHub Actions is very easy by using the run action:
- run: | curl -Lo bicepinstall https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64 chmod +x ./bicepinstall sudo mv ./bicepinstall /usr/local/bin/bicep bicep --help
With bicep installed the bicep commands can be executed this is validated by running the "bicep --help" at the end of the installation run. To run bicep against one of the bicep files we add a separate action.
- run: bicep build ./bicep/storage.bicep
In the above action the bicep file in my repository is build and saved in the same location.
Completing the GitHub workflow
With the possibility to build the bicep files in the pipeline the GitHub workflow can be completed to copy the generated ARM templates to the workflow artifacts location. These last steps are included in the sample workflow file below.
name: CI # Controls when the action will run. on: # Triggers the workflow on push or pull request events but only for the main branch push: branches: [ main ] pull_request: branches: [ main ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" build: # The type of runner that the job will run on runs-on: ubuntu-latest # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - run: | curl -Lo bicepinstall https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64 chmod +x ./bicepinstall sudo mv ./bicepinstall /usr/local/bin/bicep bicep --help - run: bicep build ./bicep/storage.bicep - name: Archive production artifacts uses: actions/upload-artifact@v2 with: name: dist-without-markdown path: ./**/*.json
The complete example can be found on GitHub: