Skip to content

Commit

Permalink
split build-kustomize-libarry from create-release
Browse files Browse the repository at this point in the history
  • Loading branch information
antoooks committed Feb 4, 2024
1 parent 4ba6897 commit e0d22ec
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 81 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/release-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ jobs:
name: Release
runs-on: ubuntu-latest
needs: build
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
permissions:
contents: write
steps:
Expand Down Expand Up @@ -120,4 +122,10 @@ jobs:
changelog_file=$(mktemp)
currentBranch=$(git rev-parse --abbrev-ref HEAD)
currentTag=${currentBranch#*-}
./releasing/compile-changelog.sh "api" "${currentTag}" "${changelog_file}"
./releasing/compile-changelog.sh "api" "${currentTag}" "${changelog_file}"
# Create github releases
gh release create "${currentTag}" \
--title "${currentTag}" \
--draft \
--notes-file "${changelog_file}"
8 changes: 7 additions & 1 deletion .github/workflows/release-cmd-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,10 @@ jobs:
changelog_file=$(mktemp)
currentBranch=$(git rev-parse --abbrev-ref HEAD)
currentTag=${currentBranch#*-}
./releasing/compile-changelog.sh "cmd/config" "${currentTag}" "${changelog_file}"
./releasing/compile-changelog.sh "cmd/config" "${currentTag}" "${changelog_file}"
# Create github releases
gh release create "${currentTag}" \
--title "${currentTag}" \
--draft \
--notes-file "${changelog_file}"
11 changes: 6 additions & 5 deletions .github/workflows/release-kustomize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
name: Build
runs-on: ubuntu-latest
needs: pre-build
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
steps:
- name: Fetch changes
uses: actions/checkout@v4
Expand Down Expand Up @@ -89,6 +91,8 @@ jobs:
name: Release
runs-on: ubuntu-latest
needs: build
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
permissions:
contents: write
steps:
Expand All @@ -112,11 +116,8 @@ jobs:
# Release kustomize
make install-local-tools
gorepomod release kustomize ${{ inputs.release_type }} --local --doIt
- name: Create release changelog
- name: Build kustomize library and create release
run: |
# Create release draft
changelog_file=$(mktemp)
currentBranch=$(git rev-parse --abbrev-ref HEAD)
currentTag=${currentBranch#*-}
./releasing/compile-changelog.sh "kustomize" "${currentTag}" "${changelog_file}"
./releasing/build-kustomize-library.sh
10 changes: 10 additions & 0 deletions .github/workflows/release-kyaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ jobs:
release:
name: Release
needs: build
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down Expand Up @@ -98,3 +100,11 @@ jobs:
currentBranch=$(git rev-parse --abbrev-ref HEAD)
currentTag=${currentBranch#*-}
./releasing/compile-changelog.sh "kyaml" "${currentTag}" "${changelog_file}"
# Create github releases
gh release create "${currentTag}" \
--title "${currentTag}" \
--draft \
--notes-file "${changelog_file}"
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
79 changes: 79 additions & 0 deletions releasing/build-kustomize-library.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash
# Copyright 2024 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0

# Build the release binaries for every OS/arch combination.
# It builds compressed artifacts on $release_dir.
function build_kustomize_binary {
echo "build kustomize binaries"
version=$1

release_dir=$2
echo "build release artifacts to $release_dir"

mkdir -p "output"
# build date in ISO8601 format
build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
for os in linux darwin windows; do
arch_list=(amd64 arm64)
if [ "$os" == "linux" ]; then
arch_list=(amd64 arm64 s390x ppc64le)
fi
for arch in "${arch_list[@]}" ; do
echo "Building $os-$arch"
# CGO_ENABLED=0 GOWORK=off GOOS=$os GOARCH=$arch go build -o output/kustomize -ldflags\
binary_name="kustomize"
[[ "$os" == "windows" ]] && binary_name="kustomize.exe"
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o output/$binary_name -ldflags\
"-s -w\
-X sigs.k8s.io/kustomize/api/provenance.version=$version\
-X sigs.k8s.io/kustomize/api/provenance.gitCommit=$(git rev-parse HEAD)\
-X sigs.k8s.io/kustomize/api/provenance.buildDate=$build_date"\
kustomize/main.go
if [ "$os" == "windows" ]; then
zip -j "${release_dir}/kustomize_${version}_${os}_${arch}.zip" output/$binary_name
else
tar cvfz "${release_dir}/kustomize_${version}_${os}_${arch}.tar.gz" -C output $binary_name
fi
rm output/$binary_name
done
done

# create checksums.txt
pushd "${release_dir}"
for release in *; do
echo "generate checksum: $release"
sha256sum "$release" >> checksums.txt
done
popd

rmdir output
}

main() {

currentBranch=$(git rev-parse --abbrev-ref HEAD)
currentTag=${currentBranch#*-}
version=${currentBranch##*/}

if grep -q -E '^[0-9]+(\.[0-9]+)*$' <<< "$version"
then
printf "%s is NOT in semver format.\n" "$version"
exit 1
fi

release_artifact_dir=$(mktemp -d)

additional_release_artifacts_arg=("$release_artifact_dir"/*)

build_kustomize_binary "${version}" "${release_artifact_dir}"

# create github releases
gh release create "${currentTag}" \
--title "${currentTag}"\
--draft \
--notes-file "${changelog_file}"\
"${additional_release_artifacts_arg[@]}"
}

main $@
74 changes: 0 additions & 74 deletions releasing/create-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,54 +35,6 @@ elif [[ ! "${RELEASE_TYPES[*]}" =~ "${2}" ]]; then
exit 1
fi

# Build the release binaries for every OS/arch combination.
# It builds compressed artifacts on $release_dir.
function build_kustomize_binary {
echo "build kustomize binaries"
version=$1

release_dir=$2
echo "build release artifacts to $release_dir"

mkdir -p "output"
# build date in ISO8601 format
build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
for os in linux darwin windows; do
arch_list=(amd64 arm64)
if [ "$os" == "linux" ]; then
arch_list=(amd64 arm64 s390x ppc64le)
fi
for arch in "${arch_list[@]}" ; do
echo "Building $os-$arch"
# CGO_ENABLED=0 GOWORK=off GOOS=$os GOARCH=$arch go build -o output/kustomize -ldflags\
binary_name="kustomize"
[[ "$os" == "windows" ]] && binary_name="kustomize.exe"
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o output/$binary_name -ldflags\
"-s -w\
-X sigs.k8s.io/kustomize/api/provenance.version=$version\
-X sigs.k8s.io/kustomize/api/provenance.gitCommit=$(git rev-parse HEAD)\
-X sigs.k8s.io/kustomize/api/provenance.buildDate=$build_date"\
kustomize/main.go
if [ "$os" == "windows" ]; then
zip -j "${release_dir}/kustomize_${version}_${os}_${arch}.zip" output/$binary_name
else
tar cvfz "${release_dir}/kustomize_${version}_${os}_${arch}.tar.gz" -C output $binary_name
fi
rm output/$binary_name
done
done

# create checksums.txt
pushd "${release_dir}"
for release in *; do
echo "generate checksum: $release"
sha256sum "$release" >> checksums.txt
done
popd

rmdir output
}

function create_release {

# Take everything before the last slash.
Expand All @@ -97,34 +49,8 @@ function create_release {
git commit -a -m "create release branch $release_branch" || true
git push -f origin $release_branch

additional_release_artifacts_arg=""

# Trigger workflow for respective modeule release
gh workflow run "release-${module_slugified}.yml" -f "release_type=${release_type}" -f "release_branch=${release_branch}"

# build `kustomize` binary
if [[ "$module" == "kustomize" ]]; then
release_artifact_dir=$(mktemp -d)
build_kustomize_binary "$nextVersion" "$release_artifact_dir"

# additional_release_artifacts_arg+="$release_artifact_dir/*"
additional_release_artifacts_arg=("$release_artifact_dir"/*)

# create github releases
gh release create "$git_tag" \
--title "$git_tag"\
--draft \
--notes-file "$changelog_file"\
"${additional_release_artifacts_arg[@]}"

return
fi

# create github releases
gh release create "$git_tag" \
--title "$git_tag"\
--draft \
--notes-file "$changelog_file"
}

function determineNextVersion {
Expand Down

0 comments on commit e0d22ec

Please sign in to comment.