From e19f1c9107ef5c7eacaba96c6e1a30f19dd5f8b7 Mon Sep 17 00:00:00 2001 From: Michael Sprengel Date: Wed, 29 Nov 2023 17:51:57 +0100 Subject: [PATCH 1/3] Add build workflow parameter build_profiles for changing the build profiles --- .github/workflows/build_pkg.yml | 9 +++++++++ container/bin/build_archdep | 2 ++ container/bin/build_indep | 2 ++ container/bin/build_source | 5 ++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_pkg.yml b/.github/workflows/build_pkg.yml index 29a94b8..8f60a10 100644 --- a/.github/workflows/build_pkg.yml +++ b/.github/workflows/build_pkg.yml @@ -11,6 +11,12 @@ on: build_container: type: string default: ghcr.io/gardenlinux/package-build + build_options: + type: string + default: "" + build_profiles: + type: string + default: "" source: type: string default: "" @@ -40,6 +46,7 @@ jobs: source_name: ${{ steps.build.outputs.source_name }} source_version: ${{ steps.build.outputs.source_version }} build_options: ${{ steps.build.outputs.build_options }} + build_profiles: ${{ steps.build.outputs.build_profiles }} release: ${{ steps.release.outputs.release }} runs-on: ubuntu-latest steps: @@ -86,6 +93,7 @@ jobs: )" echo "pkg=$pkg" | tee -a "$GITHUB_OUTPUT" echo "build_options=$(cat output/.build_options)" | tee -a "$GITHUB_OUTPUT" + echo "build_profiles=$(cat output/.build_profiles)" | tee -a "$GITHUB_OUTPUT" echo "source_name=$(cat output/.source_name)" | tee -a "$GITHUB_OUTPUT" echo "source_version=$(cat output/.source_version)" | tee -a "$GITHUB_OUTPUT" - name: upload source packages @@ -125,6 +133,7 @@ jobs: run: | cd input/ echo "${{ needs.source.outputs.build_options }}" > .build_options + echo "${{ needs.source.outputs.build_profiles}}" > .build_profiles ln -s "${{ needs.source.outputs.pkg }}.dsc" .source - name: fetch dependencies run: | diff --git a/container/bin/build_archdep b/container/bin/build_archdep index a5d02c9..b7931cb 100755 --- a/container/bin/build_archdep +++ b/container/bin/build_archdep @@ -8,7 +8,9 @@ exec 1>&2 main() ( input_dir="${1:-/input}" DEB_BUILD_OPTIONS="$(cat "$input_dir/.build_options")" + DEB_BUILD_PROFILES="$(cat "$input_dir/.build_profiles")" export DEB_BUILD_OPTIONS + export DEB_BUILD_PROFILES dsc="$(realpath "$input_dir/.source")" dpkg_arch="$(dpkg --print-architecture)" diff --git a/container/bin/build_indep b/container/bin/build_indep index a918ecb..e9d27dd 100755 --- a/container/bin/build_indep +++ b/container/bin/build_indep @@ -8,7 +8,9 @@ exec 1>&2 main() ( input_dir="${1:-/input}" DEB_BUILD_OPTIONS="$(cat "$input_dir/.build_options")" + DEB_BUILD_PROFILES="$(cat "$input_dir/.build_profiles")" export DEB_BUILD_OPTIONS + export DEB_BUILD_PROFILES dsc="$(realpath "$input_dir/.source")" dsc_arch="$(grep -oP '(?<=^Architecture: ).*' < "$dsc" | tr ' ' '\n')" diff --git a/container/bin/build_source b/container/bin/build_source index d4c8869..ccf0dd4 100755 --- a/container/bin/build_source +++ b/container/bin/build_source @@ -19,9 +19,11 @@ main() ( source="$(yq -r '.jobs.build_pkg.with.source // "'$name'"' < "$inputs_file")" debian_source="$(yq -r '.jobs.build_pkg.with.debian_source // "'$debian_source'"' < "$inputs_file")" build_options="terse $(yq -r '.jobs.build_pkg.with.build_options // ""' < "$inputs_file")" + build_profiles="$(yq -r '.jobs.build_pkg.with.build_profiles // ""' < "$inputs_file")" # Define Build Options export DEB_BUILD_OPTIONS="$build_options" + export DEB_BUILD_PROFILES="$build_profiles" # Set permissions git -C /input config --global --add safe.directory '*' @@ -64,13 +66,14 @@ main() ( # Add some meta files next to the created artifacts echo "$DEB_BUILD_OPTIONS" > .build_options + echo "$DEB_BUILD_PROFILES" > .build_profiles echo "${pkg}" > .source_name echo "${version}" > .source_version ln -s "${pkg}_${version}.dsc" .source # Copy all artifacts to the dedicated output directory if [ -d "/output" ]; then - { echo .build_options; echo .source_name; echo .source_version; echo .source; echo "${pkg}_${version}.dsc"; get_files < "${pkg}_${version}.dsc"; } | while read file; do + { echo .build_options; echo .build_profiles; echo .source_name; echo .source_version; echo .source; echo "${pkg}_${version}.dsc"; get_files < "${pkg}_${version}.dsc"; } | while read file; do sudo cp -d "$file" "/output/$file" done fi From b6503b546fc88e84acec2a4016c99239b97fecf6 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Wed, 29 Nov 2023 14:52:32 +0100 Subject: [PATCH 2/3] Create debian/changelog if not exist. --- .github/workflows/build_pkg.yml | 6 ++++++ container/bin/build_source | 26 +++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_pkg.yml b/.github/workflows/build_pkg.yml index 8f60a10..ae6661b 100644 --- a/.github/workflows/build_pkg.yml +++ b/.github/workflows/build_pkg.yml @@ -38,6 +38,12 @@ on: message: type: string default: "" + tag_suffix: + type: string + default: "" + tag_mangel: + type: string + default: "" jobs: source: name: source package diff --git a/container/bin/build_source b/container/bin/build_source index ccf0dd4..ab3fd36 100755 --- a/container/bin/build_source +++ b/container/bin/build_source @@ -20,6 +20,8 @@ main() ( debian_source="$(yq -r '.jobs.build_pkg.with.debian_source // "'$debian_source'"' < "$inputs_file")" build_options="terse $(yq -r '.jobs.build_pkg.with.build_options // ""' < "$inputs_file")" build_profiles="$(yq -r '.jobs.build_pkg.with.build_profiles // ""' < "$inputs_file")" + tag_suffix="$(yq -r '.jobs.build_pkg.with.tag_suffix // ""' < "$inputs_file")" + tag_mangle="$(yq -r '.jobs.build_pkg.with.tag_mangle // ""' < "$inputs_file")" # Define Build Options export DEB_BUILD_OPTIONS="$build_options" @@ -144,7 +146,15 @@ apply_patches() ( distribution="$(yq -r '.jobs.build_pkg.with.distribution // "'"$distribution"'"' < "$inputs_file")" message="$(yq -r '.jobs.build_pkg.with.message // "'"$message"'"' < "$inputs_file")" - DEBEMAIL="$email" DEBFULLNAME="$maintainer" dch --newversion "$(get_version)" --distribution "$distribution" --force-distribution -- "$message" + if [ -f debian/changelog ]; then + DEBEMAIL="$email" DEBFULLNAME="$maintainer" dch \ + --newversion "$(get_version)" --distribution "$distribution" \ + --force-distribution -- "$message" + else + DEBEMAIL="$email" DEBFULLNAME="$maintainer" EDITOR=true dch --create --package $name \ + --newversion "$(get_version)" --distribution "$distribution" \ + --force-distribution -- "$message" + fi if [ -x "$1/exec.post" ]; then SOURCE="$source" "$1/exec.post" @@ -152,7 +162,7 @@ apply_patches() ( ) get_sources() ( - local source=$1 + #local source=$1 # What kind of source do we have? if [[ "$source" = "git+"* ]]; then @@ -164,6 +174,12 @@ get_sources() ( fi ) +get_upstream-version() ( + IFS='#' read -r url ref <<< "${source#git+}" + git ls-remote --tags --refs $url "$tag_suffix"* | awk -F/ '{ print $3 }' | \ + grep -Ev "$tag_mangle" | tail -1 | sed -e s/"$tag_suffix"// +) + get_version() ( local version=$PACKAGE_VERSION @@ -171,7 +187,11 @@ get_version() ( # the version of the upstream package and add # the git tag to it. if [ -z "$version" ]; then - package_version=$(dpkg-parsechangelog --show-field Version) + if [ -f /input/debian/changelog ]; then + package_version=$(dpkg-parsechangelog --show-field Version) + else + package_version=$(get_upstream-version) + fi commit_hash=$(git -C /input rev-parse HEAD) # No version has been provided. Check if there is already a Garden Linux version 0 From f9007ded19ab98f4fb6d2f9e62638b3112c9615e Mon Sep 17 00:00:00 2001 From: Michael Sprengel Date: Fri, 1 Dec 2023 15:11:29 +0100 Subject: [PATCH 3/3] Enhance build_source for working with git --- container/apt/apt.conf.d/00default-release | 1 - container/apt/preferences.d/gardenlinux | 3 + .../apt/sources.list.d/gardenlinux.sources | 4 + container/apt/trusted.gpg.d/gardenlinux.asc | 29 ++++++ container/bin/build_source | 89 ++++++++++++------- 5 files changed, 92 insertions(+), 34 deletions(-) delete mode 100644 container/apt/apt.conf.d/00default-release create mode 100644 container/apt/preferences.d/gardenlinux create mode 100644 container/apt/sources.list.d/gardenlinux.sources create mode 100644 container/apt/trusted.gpg.d/gardenlinux.asc diff --git a/container/apt/apt.conf.d/00default-release b/container/apt/apt.conf.d/00default-release deleted file mode 100644 index 6d8ece5..0000000 --- a/container/apt/apt.conf.d/00default-release +++ /dev/null @@ -1 +0,0 @@ -APT::Default-Release "testing"; \ No newline at end of file diff --git a/container/apt/preferences.d/gardenlinux b/container/apt/preferences.d/gardenlinux new file mode 100644 index 0000000..2f4e912 --- /dev/null +++ b/container/apt/preferences.d/gardenlinux @@ -0,0 +1,3 @@ +Package: * +Pin: release o=Gardenlinux +Pin-Priority: 700 \ No newline at end of file diff --git a/container/apt/sources.list.d/gardenlinux.sources b/container/apt/sources.list.d/gardenlinux.sources new file mode 100644 index 0000000..5f1fe4e --- /dev/null +++ b/container/apt/sources.list.d/gardenlinux.sources @@ -0,0 +1,4 @@ +Types: deb +URIs: http://repo.gardenlinux.io/gardenlinux +Suites: today +Components: main \ No newline at end of file diff --git a/container/apt/trusted.gpg.d/gardenlinux.asc b/container/apt/trusted.gpg.d/gardenlinux.asc new file mode 100644 index 0000000..48146db --- /dev/null +++ b/container/apt/trusted.gpg.d/gardenlinux.asc @@ -0,0 +1,29 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBGN3UG4BEACUPRC/gZekjtoaszk7+TdJUi4E6U9asuUu2p9TvXpItQHcjBc4 +XZhKvrtJotft/KJQf7/hkS587QfaRzMqzIJe7WC3ttm/SWNQee9VDUOzNCBaIPrq +9iv0wZn+UtfbnKqUj8oknuo4BIKBdMJML4WiAsueP2wIrl0K37axoXfBFRXXmIhd +48xZKGw3MeoZKhv5buATwv7tnJAlWXmSAn1lJolVhcdsl6npN1RPWAUPbhUoeaYQ +zA2crak8PSe9B2foCoJ/7a4wtN4f9aI2+XYbMa97/9UzbcH8c1Cx4hSQpc7p0Csf +5Ig0h/dLAFQ11xPbCgchh6EqZY46327H5vEXxhNVOAoQqIp+MEW12Gok6fDJX4Ts +zA8k4X8w5SEdhCKd4sUBYU8CzlejXqykHRkqlYi/kR4qAUsbaNy3naIqGb+hdeSs +1Ch7X5sXArK1ua6a2xTlzpV7UesQddR31XBxg1y8zuqkD4YhxbcLx9i27kC9pyYm +5aCE215k9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DReBrA== +=93j9 +-----END PGP PUBLIC KEY BLOCK----- diff --git a/container/bin/build_source b/container/bin/build_source index 562ede6..77ebfb8 100755 --- a/container/bin/build_source +++ b/container/bin/build_source @@ -20,7 +20,7 @@ main() ( debian_source="$(yq -r '.jobs.build_pkg.with.debian_source // "'$debian_source'"' < "$inputs_file")" build_options="terse $(yq -r '.jobs.build_pkg.with.build_options // ""' < "$inputs_file")" build_profiles="$(yq -r '.jobs.build_pkg.with.build_profiles // ""' < "$inputs_file")" - git_filter="$(yq -r '.jobs.build_pkg.with.git_filter // "(.*)"' < "$inputs_file")" + git_filter="$(yq -r '.jobs.build_pkg.with.git_filter // ".*"' < "$inputs_file")" git_tag_match="$(yq -r '.jobs.build_pkg.with.git_tag_match // "(.*)"' < "$inputs_file")" # Define Build Options @@ -85,7 +85,7 @@ main() ( ) apt_source() ( - apt-get source --only-source --download-only "$1" + apt-get source -o APT::Default-Release="testing" --only-source --download-only "$1" orig=(*.orig.tar.*) debian=(*.debian.tar.*) dsc=(*.dsc) @@ -104,8 +104,8 @@ apt_source() ( git_source() ( IFS='#' read -r url ref <<< "$1" - git clone --depth 1 --bare --branch "$(get_latest_tag)" --depth 1 "$url" src.git - GIT_DIR=src.git git archive --prefix src/ "$(get_latest_tag)" > orig.tar + git clone "$url" src.git + git -C src.git archive --prefix src/ "$(get_git_tag)" > orig.tar rm -rf src.git tar -x < orig.tar ) @@ -174,39 +174,61 @@ get_sources() ( fi ) -get_tag_version() ( +get_git_tag() ( local tag if [ -z $PACKAGE_VERSION ]; then - tag=$(get_latest_tag) + tag=$(get_latest_git_tag) else - tag=$(get_tag_by_version ${PACKAGE_VERSION#gardenlinux.*}) + tag=$(get_git_tag_by_version ${PACKAGE_VERSION%-0gardenlinux*}) fi echo $tag ) -get_latest_tag() ( - IFS='#' read -r url ref <<< "${source_type#git+}" - echo $(git ls-remote --tags --refs $url | sed "s#.*\/##" | \ - grep -E "$git_filter" | | sort -V | tail -n1) - #grep -E "$git_filter" | sed -E "s#$git_tag_match#\1#" | sort -V | tail -n1) +get_latest_git_tag() ( + local latest_tag + + IFS='#' read -r url ref <<< "${source#git+}" + latest_tag="$(git ls-remote --tags --refs $url | sed "s#.*\/##" | grep -E "$git_filter" | sort -V | tail -n1)" + + echo $latest_tag +) + +get_version_by_git_tag() ( + local version tag + tag=$1 + + version=$(echo $tag | sed -E "s#$git_tag_match#\1#") + echo $version +) + +get_git_tag_by_version() ( + local tag tags version + version=$1 + + IFS='#' read -r url ref <<< "${source#git+}" + tags=$(git ls-remote --tags --refs $url | sed "s#.*\/##" | grep -E "$git_filter") + + for t in $tags; do + if [ "$(get_version_by_git_tag $t)" == "$version" ]; then + echo $t + exit 0 + fi + done ) get_upstream_version() ( local source_type=$1 + local upstream_version # What kind of source type do we have? - if [[ "$source_type" = "git+"* ]]; then - get_latest_tag + if [[ "$source_type" = "git+"* ]]; then + latest_tag=$(get_latest_git_tag) + upstream_version="$(get_version_by_git_tag $latest_tag)-0" else - native_source - fi - - # Append revision -0 on fetched latest git tagged version - # use -0 to keep it less than revision -1 from debian - # this allows us to use debian version in ther future - latest_tag=$(get_latest_tag) - package_version="${latest_tag}-0" - echo $package_version + upstream_version=$(dpkg-parsechangelog --show-field Version) + fi + + echo $upstream_version ) get_version() ( @@ -215,16 +237,17 @@ get_version() ( # If version is undefined, let's simply use # the version of the upstream package and add # the git tag to it. - - commit_hash=$(git -C /input rev-parse HEAD) - package_version=$(get_upstream_version $source_type) - - # No version has been provided. Check if there is already a Garden Linux version 0 - # if not, the current package will be the first one. Otherwise, simply use the commit hash. - if (git -C /input rev-parse --abbrev-ref HEAD | grep -qv "main") || (git -C /input tag | grep -q "gardenlinux/${package_version}gardenlinux0"); then - version="${package_version}gardenlinux~${commit_hash}" - else - version="${package_version}gardenlinux0" + if [ -z $version ]; then + commit_hash=$(git -C /input rev-parse HEAD) + package_version=$(get_upstream_version $source) + + # No version has been provided. Check if there is already a Garden Linux version 0 + # if not, the current package will be the first one. Otherwise, simply use the commit hash. + if (git -C /input rev-parse --abbrev-ref HEAD | grep -qv "main") || (git -C /input tag | grep -q "gardenlinux/${package_version}gardenlinux0"); then + version="${package_version}gardenlinux~${commit_hash}" + else + version="${package_version}gardenlinux0" + fi fi # Print the version accordingly