Skip to content

Fix release notes

Fix release notes #32

Workflow file for this run

name: Auto-Version and Deploy
on:
push:
branches:
- main
- basic-monitoring
paths-ignore:
- '**.md'
permissions:
id-token: write
contents: write
jobs:
check-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
# path: ${{ github.ref_name }}
- name: Read Version And Check
id: read_version
run: |
pwd
ls -al
version=$(cat VERSION)
echo "Version from file: $version"
# Export the version as an environment variable
echo "NEW_VERSION=$version" >> $GITHUB_ENV
# Check if the tag already exists in Git
if git rev-parse "$NEW_VERSION" >/dev/null 2>&1; then
echo "Error: Tag $NEW_VERSION already exists."
exit 1
fi
- name: Create Git Tag
if: steps.read_version.outcome == 'success'
run: |
# Tag the commit with the version and push the tag
git tag $NEW_VERSION
git push origin $NEW_VERSION
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.5.7
- name: Initialize Terraform
run: terraform init
- name: Validate Terraform
run: terraform validate
- name: Format check
run: terraform fmt -check
# Release
- name: Check for Release Notes
id: check_release_notes
continue-on-error: true
run: |
version_regex="^## ${NEW_VERSION}\$"
echo "Looking for release notes with version: '${NEW_VERSION}'"
# Extract notes for specific version, handling both middle and end cases
notes=$(awk -v ver="$version_regex" '
# Start capturing when we find our version
$0 ~ ver {capture=1; next}
# Stop capturing when we hit the next version header
/^## v/ {if(capture) exit; next}
# Print lines while capturing is active
capture {print}
' release-notes.md)
if [ -n "$notes" ]; then
{
echo 'RELEASE_NOTES<<EOF'
echo "$notes" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
echo 'EOF'
} >> $GITHUB_ENV
echo "NOTES_FOUND=true" >> $GITHUB_ENV
echo "Found release notes for version ${NEW_VERSION}:"
echo "---"
echo "$notes"
echo "---"
else
echo "NOTES_FOUND=false" >> $GITHUB_ENV
echo "No release notes found for version ${NEW_VERSION}"
fi
- name: Create GitHub Release
if: env.NOTES_FOUND == 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.NEW_VERSION }}
release_name: Release ${{ env.NEW_VERSION }}
body: ${{ env.RELEASE_NOTES }}
draft: false
prerelease: false
# - name: Check for Release Notes
# id: check_release_notes
# run: |
# version_regex="## ${NEW_VERSION}"
# echo "Looking for release notes with regex: '$version_regex'"
# notes=$(awk "/$version_regex/,/^## /{if (\$0 !~ /^## /) print}" release-notes.md)
# if [ -n "$notes" ]; then
# echo "RELEASE_NOTES=$notes" >> $GITHUB_ENV
# echo "Found release notes for version $NEW_VERSION."
# else
# echo "No release notes found for version $NEW_VERSION."
# fi
# - name: Create GitHub Release
# if: env.RELEASE_NOTES
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: ${{ env.NEW_VERSION }}
# release_name: Release ${{ env.NEW_VERSION }}
# body: ${{ env.RELEASE_NOTES }}
# draft: false
# prerelease: false
# - name: Create GitHub Release
# id: create_release
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: ${{ env.NEW_VERSION }}
# release_name: Release ${{ env.NEW_VERSION }}
# body: |
# Version ${{ env.NEW_VERSION }} of the Terraform module.
# - [x] Validated syntax
# - [x] Terraform formatted
# - [x] Ready for use
# draft: false
# prerelease: false
# - name: Read and Bump Version
# id: bump
# run: |
# # Read the current version from the VERSION file
# echo "started"
# git status
# pwd
# ls -la
# version=$(cat VERSION)
# echo "version: $version"
# # Extract major, minor, and patch
# major=$(echo $version | cut -d '.' -f 1 | sed 's/v//')
# minor=$(echo $version | cut -d '.' -f 2)
# patch=$(echo $version | cut -d '.' -f 3)
# # Logic for bumping version
# if [[ "$patch" == "x" ]]; then
# patch=0
# else
# patch=$((patch + 1))
# fi
# # Format new version as v<major>.<minor>.<patch>
# new_version="v${major}.${minor}.${patch}"
# # Write the new version to the VERSION file and commit
# echo $new_version > VERSION
# echo "version: $new_version"
# git config --local user.name "github-actions"
# git config --local user.email "[email protected]"
# git commit -am "Bump version to $new_version"
# # Create a new git tag
# git tag $new_version
# git push origin $new_version
# echo "NEW_VERSION=$new_version" >> $GITHUB_ENV