mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-30 12:38:17 +01:00
853e3d5fff
When release, this workflow will be triggered to complete subsequent work. 1 Push harbor images to dockerhub. 2 Upload asset to release. 3 Generate release notes using the .github/release.yml template. Signed-off-by: Yang Jiao <jiaoya@vmware.com>
87 lines
2.7 KiB
Bash
87 lines
2.7 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
function getAssets {
|
|
local bucket=$1
|
|
local branch=$2
|
|
local offlinePackage=$3
|
|
local onlinePackage=$4
|
|
local prerelease=$5
|
|
local assetsPath=$6
|
|
mkdir $assetsPath && pushd $assetsPath
|
|
gsutil cp gs://$bucket/$branch/$offlinePackage .
|
|
gsutil cp gs://$bucket/$branch/$offlinePackage.asc .
|
|
md5sum $offlinePackage > md5sum
|
|
md5sum $offlinePackage.asc >> md5sum
|
|
# Pre-release does not handle online installer packages
|
|
if [ $prerelease = "false" ]
|
|
then
|
|
gsutil cp gs://$bucket/$branch/$onlinePackage .
|
|
gsutil cp gs://$bucket/$branch/$onlinePackage.asc .
|
|
md5sum $onlinePackage >> md5sum
|
|
md5sum $onlinePackage.asc >> md5sum
|
|
fi
|
|
popd
|
|
}
|
|
|
|
function generateReleaseNotes {
|
|
# Use .github/release.yml configuration to generate release notes for preTag to curTag
|
|
local curTag=$1
|
|
local preTag=$2
|
|
local token=$3
|
|
local releaseNotesPath=$4
|
|
set +e
|
|
# Calculate preTag if preTag is null
|
|
# If curTag is v2.5.0-rc1 then preTag is v2.4.0
|
|
# If curTag is v2.5.1 then preTag is v2.5.0
|
|
if [ $preTag = "null" ]
|
|
then
|
|
IFS='.' read -r -a curTagArray <<< $curTag
|
|
IFS='-' read -r -a patch <<< ${curTagArray[2]}
|
|
local tagMajor=${curTagArray[0]}
|
|
local tagMinor=${curTagArray[1]}
|
|
local tagPatch=${patch[0]}
|
|
if [ $tagPatch -gt 0 ]
|
|
then
|
|
preTag="$tagMajor.$tagMinor.$(expr $tagPatch - 1)"
|
|
else
|
|
preTag="$tagMajor.$(expr $tagMinor - 1).$tagPatch"
|
|
fi
|
|
fi
|
|
set -e
|
|
release=$(curl -X POST -H "Authorization: token $token" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/goharbor/harbor/releases/generate-notes -d '{"tag_name":"'$curTag'","previous_tag_name":"'$preTag'"}' | jq '.body' | tr -d '"')
|
|
echo -e $release > $releaseNotesPath
|
|
}
|
|
|
|
function publishImages {
|
|
# Create curTag and push it to the goharbor namespace of dockerhub
|
|
local curTag=$1
|
|
local baseTag=$2
|
|
local dockerHubUser=$3
|
|
local dockerHubPassword=$4
|
|
docker login -u $dockerHubUser -p $dockerHubPassword
|
|
local images="$(docker images --format "{{.Repository}}" --filter=reference='goharbor/*:'$baseTag'')"
|
|
for image in $images
|
|
do
|
|
echo "push image: $image"
|
|
docker tag $image:$baseTag $image:$curTag
|
|
retry 5 docker push $image:$curTag
|
|
done
|
|
docker logout
|
|
}
|
|
|
|
function retry {
|
|
local -r -i max="$1"; shift
|
|
local -i n=1
|
|
until "$@"
|
|
do
|
|
if ((n==max))
|
|
then
|
|
echo "fail with $n times try..."
|
|
return 1
|
|
else
|
|
echo "failed, trying again in $n seconds..."
|
|
sleep $((n++))
|
|
fi
|
|
done
|
|
} |