Merge pull request #5 from EUCPilots/updates #28
This file contains hidden or 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: 'Tag on version bump' | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'EvergreenUI/EvergreenUI.psd1' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| tag: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract version from manifest | |
| id: version | |
| run: | | |
| FULL_VERSION=$(sed -n "4p" EvergreenUI/EvergreenUI.psd1 | grep -oP "'\K[^']+" | tr -d '\r') | |
| echo "full_version=$FULL_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "Detected version: $FULL_VERSION" | |
| - name: Determine if tagging is required | |
| id: check | |
| run: | | |
| FULL_VERSION="${{ steps.version.outputs.full_version }}" | |
| TAG_NAME="v${FULL_VERSION}" | |
| # Skip if this exact tag already exists | |
| if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then | |
| echo "Tag $TAG_NAME already exists. Skipping." | |
| echo "should_tag=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| # Get the latest semver tag | |
| LATEST_TAG=$(git tag --list 'v*' --sort=-v:refname | head -n 1) | |
| if [ -z "$LATEST_TAG" ]; then | |
| echo "No existing tags found. Will create $TAG_NAME" | |
| echo "should_tag=true" >> "$GITHUB_OUTPUT" | |
| echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| # Strip the leading 'v' for comparison | |
| LATEST_VERSION="${LATEST_TAG#v}" | |
| # Determine the higher of the two versions | |
| HIGHER=$(printf '%s\n%s\n' "$LATEST_VERSION" "$FULL_VERSION" | sort -V | tail -n 1) | |
| if [ "$HIGHER" = "$FULL_VERSION" ] && [ "$FULL_VERSION" != "$LATEST_VERSION" ]; then | |
| echo "Version $FULL_VERSION is higher than latest tag $LATEST_TAG. Will create $TAG_NAME" | |
| echo "should_tag=true" >> "$GITHUB_OUTPUT" | |
| echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "Version $FULL_VERSION is not higher than latest tag $LATEST_TAG. Skipping." | |
| echo "should_tag=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Create and push tag | |
| if: steps.check.outputs.should_tag == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag "${{ steps.check.outputs.tag_name }}" | |
| git push origin "${{ steps.check.outputs.tag_name }}" | |
| echo "Created tag ${{ steps.check.outputs.tag_name }}" |