Add Basic monitoring and Release Pipeline #49
Workflow file for this run
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: Auto-Version and Deploy | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- '**.md' | |
pull_request: | |
types: [opened, synchronize] | |
permissions: | |
id-token: write | |
contents: write | |
pull-requests: read | |
jobs: | |
check-and-release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
fetch-tags: true | |
- name: Read Version | |
id: read_version | |
run: | | |
pwd | |
ls -la | |
git status | |
# Read the version from the VERSION file | |
version=$(cat VERSION) | |
echo "NEW_VERSION=$version" >> $GITHUB_ENV | |
- name: Read Version And Check | |
id: check_tag | |
run: | | |
# 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 | |
else | |
echo "Tag $NEW_VERSION will be created when merging is cpompleted." | |
fi | |
- 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 | |
# Tag and Release | |
- name: Create Git Tag | |
if: github.event_name == 'push' && success() | |
# if: steps.check_tag.outcome == 'success' | |
run: | | |
# Tag the commit with the version and push the tag | |
git tag $NEW_VERSION | |
git push origin $NEW_VERSION | |
- name: Check for Release Notes | |
if: github.event_name == 'push' && success() | |
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 target version | |
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' && github.event_name == 'push' && success() | |
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 |