-
Notifications
You must be signed in to change notification settings - Fork 98
133 lines (107 loc) · 5.68 KB
/
update-version.yml
File metadata and controls
133 lines (107 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Sync LTFS Version with Upstream
on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
permissions:
contents: write
pull-requests: write
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
# Check if commit message contains "release-tag"
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "Latest commit message: $COMMIT_MSG"
if echo "$COMMIT_MSG" | grep -q "release-tag"; then
echo "Commit contains 'release-tag' keyword - skipping update"
echo "needs_update=false" >> $GITHUB_OUTPUT
exit 0
fi
# Extract the value inside parentheses from current version
PAREN_VALUE=$(echo "$CURRENT_VERSION" | sed -E 's/.*\(([^)]+)\).*/\1/')
echo "Value in parentheses: $PAREN_VALUE"
# Check if the value in parentheses is a number
if ! echo "$PAREN_VALUE" | grep -qE '^[0-9]+$'; then
echo "Value in parentheses is not a number (likely 'Prelim') - no update needed"
echo "needs_update=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "Value in parentheses is a number - proceeding with update"
# Extract version number without parentheses (e.g., "2.4.8.2" from "2.4.8.2 (10520)")
VERSION_BASE=$(echo "$CURRENT_VERSION" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*/\1/')
echo "Base version: $VERSION_BASE"
# Increment the last number in the version
LAST_NUM=$(echo "$VERSION_BASE" | awk -F. '{print $NF}')
NEW_LAST_NUM=$((LAST_NUM + 1))
NEW_VERSION=$(echo "$VERSION_BASE" | sed -E "s/\.[0-9]+$/.$NEW_LAST_NUM/")
NEW_VERSION_WITH_PRELIM="$NEW_VERSION (Prelim)"
echo "New version: $NEW_VERSION_WITH_PRELIM"
echo "new_version=$NEW_VERSION_WITH_PRELIM" >> $GITHUB_OUTPUT
echo "needs_update=true" >> $GITHUB_OUTPUT
- name: Update configure.ac
if: steps.check_version.outputs.needs_update == 'true'
id: update_file
run: |
VERSION="${{ steps.check_version.outputs.new_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: update version to ${{ steps.check_version.outputs.new_version }}"
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 updated** - Version changed from ${{ steps.check_version.outputs.current_version }} to ${{ steps.check_version.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "**No update needed** - Version already has 'Prelim' or commit contains 'release-tag'" >> $GITHUB_STEP_SUMMARY
fi