Skip to content

add ending new line to versions.json #38

add ending new line to versions.json

add ending new line to versions.json #38

name: Get latest release version
on:
workflow_dispatch:
push:
paths:
- "versions.json"
schedule:
- cron: "0 0 * * *"
jobs:
get-version:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
strategy:
matrix:
repository: ["hashicorp/terraform", "Azure/azure-cli"]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch release version
id: version
env:
release_url: https://api.github.com/repos/${{ matrix.repository }}/releases/latest
run: |
version=$(curl -sL ${{ env.release_url }} | jq -r '.tag_name' | tr -d 'v' | sed 's/^azure-cli-//')
repository=${{ matrix.repository }}
# Update the JSON file based on the repository
if [[ "$repository" == "hashicorp/terraform" ]] && [[ "$version" != "$(jq -r '.terraform_versions[0]' versions.json)" ]]; then
jq --arg version "$version" '.terraform_versions |= [$version] + .[:-1]' versions.json > tmp.json && mv tmp.json versions.json
elif [[ "$repository" == "Azure/azure-cli" ]] && [[ "$version" != "$(jq -r '.azure_cli_versions[0]' versions.json)" ]]; then
jq --arg version "$version" '.azure_cli_versions |= [$version] + .[:-1]' versions.json > tmp.json && mv tmp.json versions.json
fi
echo "version=$version" >> $GITHUB_OUTPUT
- name: Check for modified files
id: git-check
run: echo "modified=$([ -z "`git status --porcelain`" ] && echo "false" || echo "true")" >> $GITHUB_OUTPUT
- name: Commit latest release version
if: steps.git-check.outputs.modified == 'true'
run: |
git config --global user.name 'GitHub Action'
git config --global user.email 'action@github.com'
git commit -am "Update ${{ matrix.repository }} package version to ${{ steps.version.outputs.version }}"
git pull --rebase
git push