Improve version determination in publish workflow#5
Conversation
Update the GitHub Actions workflow to determine the version from the tag if available, or fall back to the version in gleam.toml when triggered by a merged PR. This makes the workflow more robust for different trigger scenarios.
There was a problem hiding this comment.
Pull Request Overview
This PR improves the robustness of the publish workflow by adding conditional version determination logic. The workflow now checks if it's triggered by a tag push and extracts the version from the tag, or falls back to reading the version from gleam.toml when triggered by a merged PR.
Key Changes
- Added conditional logic to check if the workflow is triggered by a tag push
- Implemented fallback to read version from
gleam.tomlwhen no tag is present - Updated step name from "Determine version from tag" to "Determine version" to reflect the broader functionality
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| VERSION=${TAG#v} | ||
| echo "Determined version ${VERSION} from tag ${TAG}" | ||
| else | ||
| VERSION=$(grep '^version' gleam.toml | sed -E 's/.*= *"([^\"]+)".*/\1/') || true |
There was a problem hiding this comment.
The escaped double quote in the character class [^\"]+ is unnecessary and incorrect. Since the sed expression is enclosed in single quotes, the backslash before the double quote is treated literally. This should be [^"]+ instead. While this may work in practice, it's technically incorrect regex syntax.
| VERSION=${TAG#v} | ||
| echo "Determined version ${VERSION} from tag ${TAG}" | ||
| else | ||
| VERSION=$(grep '^version' gleam.toml | sed -E 's/.*= *"([^\"]+)".*/\1/') || true |
There was a problem hiding this comment.
The || true at the end of this line suppresses errors and could result in an empty VERSION variable if grep or sed fails. This undermines the set -euo pipefail on line 78. Consider removing || true to allow the step to fail properly if the version cannot be determined, or add explicit validation after this line to check if VERSION is non-empty and fail with a clear error message if it's not.
| VERSION=$(grep '^version' gleam.toml | sed -E 's/.*= *"([^\"]+)".*/\1/') || true | |
| VERSION=$(grep '^version' gleam.toml | sed -E 's/.*= *"([^\"]+)".*/\1/') | |
| if [ -z "${VERSION}" ]; then | |
| echo "Error: Could not determine version from gleam.toml" >&2 | |
| exit 1 | |
| fi |
Update the GitHub Actions workflow to determine the version from the tag if available, or fall back to the version in gleam.toml when triggered by a merged PR. This makes the workflow more robust for different trigger scenarios.