Skip to content

Chore: automate init version #2

Chore: automate init version

Chore: automate init version #2

Workflow file for this run

name: Sync LTFS Version with Upstream
on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
jobs:
update-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Fetch latest tag from upstream
id: get_tag
run: |
# Fetch the latest tag from the upstream repository
LATEST_TAG=$(curl -s https://api.github.com/repos/LinearTapeFileSystem/ltfs/tags | jq -r '.[0].name')
echo "Latest tag from upstream: $LATEST_TAG"
# Extract version numbers and build number (e.g., v.2.4.8.2-10520 -> 2.4.8.2 (10520))
VERSION_NUM=$(echo "$LATEST_TAG" | sed -E 's/^v\.?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*/\1/')
BUILD_NUM=$(echo "$LATEST_TAG" | sed -E 's/^v\.?[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+-([0-9]+).*/\1/')
# Combine version with build number
if [ -n "$BUILD_NUM" ] && [ "$BUILD_NUM" != "$LATEST_TAG" ]; then
VERSION="$VERSION_NUM ($BUILD_NUM)"
else
VERSION="$VERSION_NUM"
fi
echo "Extracted version: $VERSION"
# Store in output
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check current version in configure.ac
id: check_version
run: |
# Extract current version from line 39
CURRENT_VERSION=$(sed -n '39p' configure.ac | sed -E 's/.*\[LTFS\], \[([^]]+)\].*/\1/')
echo "Current version in configure.ac: $CURRENT_VERSION"
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Compare with upstream version
UPSTREAM_VERSION="${{ steps.get_tag.outputs.version }}"
if [ "$CURRENT_VERSION" == "$UPSTREAM_VERSION" ]; then
echo "Version is up to date - no action needed"
echo "needs_update=false" >> $GITHUB_OUTPUT
else
echo "Version mismatch detected!"
echo " Current: $CURRENT_VERSION"
echo " Upstream: $UPSTREAM_VERSION"
echo "needs_update=true" >> $GITHUB_OUTPUT
fi
- name: Update configure.ac
if: steps.check_version.outputs.needs_update == 'true'
id: update_file
run: |
VERSION="${{ steps.get_tag.outputs.version }}"
# Update line 39 with the new version
sed -i "39s/\[LTFS\], \[[^]]*\]/[LTFS], [$VERSION]/" configure.ac
echo "File updated successfully"
echo "Updated line 39:"
sed -n '39p' configure.ac
- name: Commit and push changes
if: steps.check_version.outputs.needs_update == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add configure.ac
git commit -m "chore: sync configure.ac version to ${{ steps.get_tag.outputs.version }} (upstream: ${{ steps.get_tag.outputs.tag }})"
git push origin HEAD:${{ github.event.pull_request.head.ref }}
- name: Summary
run: |
echo "## Version Check Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Upstream Tag**: ${{ steps.get_tag.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "- **Upstream Version**: ${{ steps.get_tag.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Current Version**: ${{ steps.check_version.outputs.current_version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Update Needed**: ${{ steps.check_version.outputs.needs_update }}" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check_version.outputs.needs_update }}" == "true" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "**configure.ac synced** - Version updated from ${{ steps.check_version.outputs.current_version }} to ${{ steps.get_tag.outputs.version }}" >> $GITHUB_STEP_SUMMARY
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "**No sync needed** - configure.ac version already matches upstream (${{ steps.get_tag.outputs.version }})" >> $GITHUB_STEP_SUMMARY
fi