Skip to content

fix err

fix err #29

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
run: |
version_regex="## ${NEW_VERSION}"
# Debugging: Print the regex and contents of the release notes file
echo "Looking for release notes with regex: '$version_regex'"
echo "Contents of release-notes.md:"
cat release-notes.md
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
# # Search for release notes for the specified version in release-notes.md
# version_regex="## $NEW_VERSION"
# 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