Create v0.4.0-preview Release #5
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: Create Azure IoT Operations Release | |
run-name: Create ${{ github.event.inputs.version }} Release | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version to publish' | |
required: true | |
type: string | |
isDraft: | |
description: 'Whether the release should be a draft release.' | |
required: true | |
type: boolean | |
default: true | |
releaseBranchEnabled: | |
description: 'Whether the release branch creation is enabled.' | |
required: true | |
type: boolean | |
default: false | |
workflow_call: | |
inputs: | |
version: | |
description: 'Version to publish' | |
required: true | |
type: string | |
isDraft: | |
description: 'Whether the release should be a draft release.' | |
required: true | |
type: boolean | |
default: true | |
releaseBranchEnabled: | |
description: 'Whether the release branch creation is enabled.' | |
required: true | |
type: boolean | |
default: false | |
jobs: | |
ValidateRelease: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.templateVersion.outputs.version }} | |
steps: | |
- name: Verify Repo | |
run: |- | |
allowed_repositories=("Azure/azure-iot-operations-pr" "Azure/azure-iot-operations") | |
if [[ ! " ${allowed_repositories[@]} " =~ " ${{ github.repository }} " ]]; then | |
echo "::error::This workflow should not be run in this repository" | |
exit 1 | |
fi | |
if [[ "${{ github.ref }}" != "refs/heads/main" ]]; then | |
echo "::error::This workflow should only be run on the main branch" | |
exit 1 | |
fi | |
- name: Set Version | |
id: templateVersion | |
run: |- | |
set -e | |
# strip spaces from version | |
version=$(echo "${{ inputs.version }}" | tr -d '[:space:]') | |
if [[ -z "$version" ]]; then | |
echo "::error::Valid version is required" | |
fi | |
if [[ $version != v* ]]; then | |
echo "::error::Version must begin with 'v'" | |
fi | |
echo "Set version to $version" | |
echo "version=${version}" >> $GITHUB_OUTPUT | |
CreateRelease: | |
permissions: | |
contents: write | |
runs-on: ubuntu-latest | |
needs: ValidateRelease | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v1 | |
- name: Build Assets | |
id: buildAssets | |
run: |- | |
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash | |
files=() | |
if [[ -d samples/grafana-dashboards ]]; then | |
zip -r -9 grafana-dashboard.zip samples/grafana-dashboards | |
files+=("grafana-dashboard.zip") | |
fi | |
if [[ -f dev/azure-iot-operations.bicep ]]; then | |
az bicep build -f dev/azure-iot-operations.bicep | |
files+=("dev/azure-iot-operations.json") | |
elif [[ -f release/azure-iot-operations.json ]]; then | |
files+=("release/azure-iot-operations.json") | |
fi | |
if [[ -f .integration-lab/int-deployment.bicep ]]; then | |
az bicep build -f .integration-lab/int-deployment.bicep | |
files+=(".integration-lab/int-deployment.json") | |
fi | |
filelist=$(IFS=,; echo "${files[*]}") | |
echo "filelist=\"$filelist\"" >> $GITHUB_OUTPUT | |
- name: Create Release | |
id: createRelease | |
run: |- | |
set -e | |
gh auth login --with-token <<< "${{ github.token }}" | |
url=$(gh release create "${{ needs.ValidateRelease.outputs.version }}" \ | |
--latest \ | |
--target "${{ github.ref }}" \ | |
--repo "${{ github.repository }}" \ | |
--title "${{ needs.ValidateRelease.outputs.version }}" \ | |
$( ${{ inputs.isDraft }} && echo "--draft" ) \ | |
$(echo "${{ steps.buildAssets.outputs.filelist }}" | tr "," " ")) | |
echo "url=$url" >> $GITHUB_OUTPUT | |
- name: Summarize | |
run: |- | |
IFS=',' read -r -a files <<< "${{ steps.buildAssets.outputs.filelist }}" | |
echo "# Release ${{ needs.ValidateRelease.outputs.version }} created" >> $GITHUB_STEP_SUMMARY | |
echo "A draft release has been created with the following assets:" >> $GITHUB_STEP_SUMMARY | |
for file in "${files[@]}"; do | |
echo "- $file" >> $GITHUB_STEP_SUMMARY | |
done | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "The release can be found [here](${{ steps.createRelease.outputs.url }})" >> $GITHUB_STEP_SUMMARY | |
CreateReleaseBranch: | |
permissions: | |
contents: write | |
runs-on: ubuntu-latest | |
needs: CreateRelease | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v1 | |
- name: Create Release Branch | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: |- | |
set -e | |
git config --global user.email "[email protected]" | |
git config --global user.name "Azure IoT Operations Bot" | |
if [ ${{inputs.releaseBranchEnabled}} == true ]; then | |
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }} | |
git branch release/${{inputs.version}} | |
git push origin release/${{inputs.version}} | |
fi | |