Skip to content

feat: terraform provider upgrader (#30) #37

feat: terraform provider upgrader (#30)

feat: terraform provider upgrader (#30) #37

name: Semantic Versioning and Release
on:
push:
branches:
- main
workflow_dispatch:
jobs:
lint:
name: Lint
uses: ./.github/workflows/lint.yml
secrets: inherit
semantic-release:
name: Semantic Versioning and Release
runs-on: ubuntu-latest
needs: lint
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
fetch-tags: true
- name: Get current year and month month for caching
id: date
run: echo "month_year=$(date +'%m-%Y')" >> $GITHUB_OUTPUT
- name: Cache semantic-release tools
id: cache-semantic-release
uses: actions/cache@v4
with:
path: ~/.npm-semantic-release
key: npm-semantic-release-${{ runner.os }}-${{ steps.date.outputs.month_year }}-v1
restore-keys: |
npm-semantic-release-${{ runner.os }}-${{ steps.date.outputs.month_year }}-
npm-semantic-release-${{ runner.os }}-
- name: Install semantic-release and plugins
if: steps.cache-semantic-release.outputs.cache-hit != 'true'
run: |
npm config set prefix ~/.npm-semantic-release
npm install -g \
semantic-release \
@semantic-release/commit-analyzer \
@semantic-release/release-notes-generator \
@semantic-release/npm \
@semantic-release/github
- name: Add semantic-release to PATH
run: echo "$HOME/.npm-semantic-release/bin" >> $GITHUB_PATH
- name: Run semantic-release
env:
GITHUB_TOKEN: ${{ github.token }}
run: semantic-release
semantic-release-flowing-tags:
name: Add flowing tags
runs-on: ubuntu-latest
needs: semantic-release
if: github.ref == 'refs/heads/main'
permissions:
contents: write
outputs:
latest-tag: ${{ steps.latest-tag.outputs.tag }}
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
fetch-tags: true
- name: Get latest tag
id: latest-tag
run: |
git fetch --tags
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
echo "tag=$latest_tag" >> $GITHUB_OUTPUT
- name: Is tag semantic?
id: is-tag-semantic
if: steps.latest-tag.outputs.tag != ''
run: |
TAG="${{ steps.latest-tag.outputs.tag }}"
# Skip if tag doesn't match semantic version pattern
if [[ ! $TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::debug::Tag $TAG doesn't match semantic version pattern, skipping moving tags"
echo "semantic=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "semantic=true" >> $GITHUB_OUTPUT
echo "semantic-tag=$TAG" >> $GITHUB_OUTPUT
- name: Extract version tag
id: major-minor-tags
if: ${{ steps.is-tag-semantic.outputs.semantic == 'true' }}
run: |
TAG="${{ steps.is-tag-semantic.outputs.semantic-tag }}"
VERSION=${TAG#v}
IFS='.' read -ra VERSION_PARTS <<< "$VERSION"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
echo "::debug::Extracted version parts -> MAJOR=$MAJOR, MINOR=$MINOR from TAG=$TAG"
echo "major=$MAJOR" >> $GITHUB_OUTPUT
echo "minor=$MINOR" >> $GITHUB_OUTPUT
- name: Push major tag
id: push-major
if: ${{ steps.is-tag-semantic.outputs.semantic == 'true' }}
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
TAG="${{ steps.is-tag-semantic.outputs.semantic-tag }}"
MAJOR="${{ steps.major-minor-tags.outputs.major }}"
MAJOR_TAG="v$MAJOR"
echo "::debug::Creating/updating tag $MAJOR_TAG to point to $TAG"
git tag -f "$MAJOR_TAG" "$TAG"
git push origin "$MAJOR_TAG" --force
- name: Push minor tag
id: push-minor
if: ${{ steps.is-tag-semantic.outputs.semantic == 'true' }}
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
TAG="${{ steps.is-tag-semantic.outputs.semantic-tag }}"
MAJOR="${{ steps.major-minor-tags.outputs.major }}"
MINOR="${{ steps.major-minor-tags.outputs.minor }}"
MINOR_TAG="v$MAJOR.$MINOR"
echo "::debug::Creating/updating tag $MINOR_TAG to point to $TAG"
git tag -f "$MINOR_TAG" "$TAG"
git push origin "$MINOR_TAG" --force
trigger-docs-update:
name: Trigger docs tags update
runs-on: ubuntu-latest
needs: semantic-release-flowing-tags
if: github.ref == 'refs/heads/main' && needs.semantic-release-flowing-tags.outputs.latest-tag != ''
permissions:
actions: write
steps:
- name: Trigger update-tags-in-docs workflow
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
gh workflow run update-tags-in-docs.yml \
--repo ${{ github.repository }} \
--field tag=${{ needs.semantic-release-flowing-tags.outputs.latest-tag }}