Skip to content

Commit 1753a6d

Browse files
shanthooshCI Builder
andauthored
fix version as part of CI (#216)
Co-authored-by: CI Builder <[email protected]>
1 parent 0b10d87 commit 1753a6d

File tree

5 files changed

+144
-29
lines changed

5 files changed

+144
-29
lines changed

.github/workflows/java-ci.yml

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ concurrency:
5757
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
5858

5959
jobs:
60-
build:
60+
build-checks:
6161
runs-on: ubuntu-latest
6262
steps:
6363
- uses: actions/checkout@v4
@@ -67,17 +67,50 @@ jobs:
6767
with:
6868
distribution: zulu
6969
java-version: 8
70-
- run: echo -e "$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)\t$(hostname -f) $(hostname -s)" | sudo tee -a /etc/hosts
70+
- run: ./gradlew -DsparkVersions=3.5 build -x test -x javadoc -x integrationTest
7171

72-
- name: Perform release
73-
if: ${{ github.event_name == 'push'
74-
&& github.ref == 'refs/heads/openhouse-1.5.2'
75-
&& github.repository == 'linkedin/iceberg'
76-
&& !contains(toJSON(github.event.commits.*.message), '[skip release]') }}
77-
run: ./gradlew -DsparkVersions=3.5 githubRelease publishToSonatype closeAndReleaseStagingRepository -x test -x integrationTest
78-
env:
79-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
80-
SONATYPE_USER: ${{secrets.SONATYPE_USERNAME}}
81-
SONATYPE_PWD: ${{secrets.SONATYPE_PASSWORD}}
82-
PGP_KEY: ${{secrets.PGP_KEY}}
83-
PGP_PWD: ${{secrets.PGP_PWD}}
72+
release:
73+
needs: build-checks
74+
if: ${{ github.event_name == 'push' }}
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v4
78+
with:
79+
fetch-depth: 0 # REQUIRED for git describe to find tags
80+
- uses: actions/setup-java@v4
81+
with:
82+
distribution: zulu
83+
java-version: 8
84+
- run: echo -e "$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)\t$(hostname -f) $(hostname -s)" | sudo tee -a /etc/hosts
85+
86+
- name: Build for release
87+
run: ./gradlew -DsparkVersions=3.5 build -x test -x integrationTest
88+
89+
- name: Create and push version tag
90+
id: create_tag
91+
if: ${{ github.event_name == 'push'
92+
&& github.ref == 'refs/heads/openhouse-1.5.2'
93+
&& github.repository == 'linkedin/iceberg'
94+
&& !contains(toJSON(github.event.commits.*.message), '[skip release]') }}
95+
run: ./ci-create-tag.sh
96+
env:
97+
GIT_USER_NAME: "GitHub Actions"
98+
GIT_USER_EMAIL: "[email protected]"
99+
100+
- name: Perform release
101+
if: ${{ github.event_name == 'push'
102+
&& github.ref == 'refs/heads/openhouse-1.5.2'
103+
&& github.repository == 'linkedin/iceberg'
104+
&& !contains(toJSON(github.event.commits.*.message), '[skip release]') }}
105+
run: |
106+
echo "Using version: ${{ steps.create_tag.outputs.NEW_VERSION }}"
107+
./gradlew githubRelease publishToSonatype closeAndReleaseStagingRepository \
108+
-PciVersion="${{ steps.create_tag.outputs.NEW_VERSION }}" \
109+
-DsparkVersions=3.5 \
110+
-x test -x integrationTest
111+
env:
112+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113+
SONATYPE_USER: ${{ secrets.SONATYPE_USERNAME }}
114+
SONATYPE_PWD: ${{secrets.SONATYPE_PASSWORD}}
115+
PGP_KEY: ${{secrets.PGP_KEY}}
116+
PGP_PWD: ${{secrets.PGP_PWD}}

build.gradle

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
* under the License.
1818
*/
1919

20+
2021
import groovy.transform.Memoized
21-
import java.util.regex.Matcher
22-
import java.util.regex.Pattern
2322

2423
buildscript {
2524
repositories {
@@ -982,23 +981,31 @@ String getVersionFromFile() {
982981
}
983982

984983
String getProjectVersion() {
985-
if (versionFileExists()) {
986-
return getVersionFromFile()
984+
// Check if CI has provided an explicit version via -PciVersion
985+
if (project.hasProperty('ciVersion')) {
986+
String version = project.property('ciVersion')
987+
println "Version from CI: ${version.padRight(27)}"
988+
return version
987989
}
988990

989991
try {
990-
// we're fetching the version from the latest tag (prefixed with 'apache-iceberg-'),
991-
// which can look like this: '0.13.0-2-g805400f0.dirty' but we're only interested in the MAJOR.MINOR.PATCH part
992-
String version = gitVersion()
993-
Pattern pattern = Pattern.compile("^([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?\$")
994-
Matcher matcher = pattern.matcher(version)
995-
if (matcher.matches()) {
996-
// bump the MINOR version and always set the PATCH version to 0
997-
return matcher.group(1) + "." + (Integer.valueOf(matcher.group(2)) + 1) + ".0-SNAPSHOT"
992+
def stdout = new ByteArrayOutputStream()
993+
exec {
994+
commandLine 'git', 'describe', '--tags', '--abbrev=0'
995+
standardOutput = stdout
996+
}
997+
String version = stdout.toString().trim()
998+
999+
// Remove 'v' prefix if present
1000+
if (version.startsWith('v')) {
1001+
version = version.substring(1)
9981002
}
1003+
1004+
println "Version from git tag: ${version.padRight(30)}"
9991005
return version
10001006
} catch (Exception e) {
1001-
throw new Exception("Neither version.txt nor git version exists: " + e.getMessage(), e)
1007+
logger.warn("Could not determine version from git: ${e.message}")
1008+
return "0.0.0-SNAPSHOT"
10021009
}
10031010
}
10041011

ci-create-tag.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
21+
set -euo pipefail
22+
23+
echo "Fetching tags to ensure we have the latest..."
24+
git fetch --tags
25+
26+
CURRENT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0.0")
27+
echo "Current tag: $CURRENT_TAG"
28+
29+
# Normalize version (remove 'v' prefix if present)
30+
VERSION=${CURRENT_TAG#v}
31+
echo "Normalized version: $VERSION"
32+
33+
# Split version into parts (expecting MAJOR.MINOR.PATCH.BUILD)
34+
IFS='.' read -ra VERSION_PARTS <<< "$VERSION"
35+
36+
# Ensure we have 4 parts, pad with zeros if needed
37+
while [ ${#VERSION_PARTS[@]} -lt 4 ]; do
38+
VERSION_PARTS+=(0)
39+
done
40+
41+
MAJOR=${VERSION_PARTS[0]}
42+
MINOR=${VERSION_PARTS[1]}
43+
PATCH=${VERSION_PARTS[2]}
44+
BUILD=${VERSION_PARTS[3]}
45+
46+
# Increment build number
47+
BUILD=$((BUILD + 1))
48+
49+
NEW_VERSION="$MAJOR.$MINOR.$PATCH.$BUILD"
50+
NEW_TAG="v$NEW_VERSION"
51+
52+
echo "New version: $NEW_VERSION"
53+
echo "New tag: $NEW_TAG"
54+
55+
# Check if tag already exists
56+
if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then
57+
echo "Tag $NEW_TAG already exists. Skipping tag creation."
58+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
59+
exit 0
60+
fi
61+
62+
# Configure git
63+
git config user.name "github-actions[bot]"
64+
git config user.email "github-actions[bot]@users.noreply.github.com"
65+
66+
# Create annotated tag with [skip ci] to prevent infinite loop
67+
git tag -a "$NEW_TAG" -m "Release $NEW_VERSION [skip ci]"
68+
69+
# Push tag
70+
git push origin "$NEW_TAG"
71+
72+
# Export version to GitHub environment
73+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
74+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
75+
76+
echo "Successfully created and pushed tag: $NEW_TAG"

core/src/test/java/org/apache/iceberg/hadoop/TestHadoopCommits.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public void testCanReadOldCompressedManifestFiles() throws Exception {
410410
Assertions.assertThat(tasks).as("Should scan 1 files").hasSize(1);
411411
}
412412

413-
//@Test
413+
// @Test
414414
public void testConcurrentFastAppends(@TempDir File dir) throws Exception {
415415
Assertions.assertThat(version(1)).as("Should create v1 metadata").exists().isFile();
416416
int threadsCount = 5;

version.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)