Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly gather version information from git #37

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/build_pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ on:
message:
type: string
default: ""
git_filter:
type: string
default: ""
git_tag_match:
type: string
default: ""
jobs:
source:
name: source package
Expand Down
1 change: 0 additions & 1 deletion container/apt/apt.conf.d/00default-release

This file was deleted.

3 changes: 3 additions & 0 deletions container/apt/preferences.d/gardenlinux
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Package: *
Pin: release o=Gardenlinux
Pin-Priority: 700
4 changes: 4 additions & 0 deletions container/apt/sources.list.d/gardenlinux.sources
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should never be needed! if we have dependecies on other self build packages these should always be explicit through the dependencies input of the build_pkg.yml or locally the /pkgs mount in the container. otherwise we would once again have the problem with needing an incrementally build repo

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Types: deb
URIs: http://repo.gardenlinux.io/gardenlinux
Suites: today
Components: main
29 changes: 29 additions & 0 deletions container/apt/trusted.gpg.d/gardenlinux.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQINBGN3UG4BEACUPRC/gZekjtoaszk7+TdJUi4E6U9asuUu2p9TvXpItQHcjBc4
XZhKvrtJotft/KJQf7/hkS587QfaRzMqzIJe7WC3ttm/SWNQee9VDUOzNCBaIPrq
9iv0wZn+UtfbnKqUj8oknuo4BIKBdMJML4WiAsueP2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qZd1shFlxlodU8qUtoAisk+WRoHCetkFSPvLr4EVloTb
SUB7gHPBWqjrCP39lYPsN52fgBiG2Nko+bnU9BSPt5VIvYQfvX3gx0FXQbW1zeZ6
gq4w3lWajqilmS5F8x2pBJAFdLZw7f5t4w0NoGA2edJEc51+JW0/BgKmImQOjiOg
dD34FwP49P6orG14l/q3meKfJB0O660N09+liEHLo9zJtOUp8v+EwAjB81/LRLpV
HNRHTVOxDJRDDC2wjbhN38BtfjnLKFz2S/hZNIDeqz53fSgpGftdiBNhLS8wI2E1
ciUIHaRWRlvgpEo1KsHk3Knn+t+f+5Fxyi9Yj9QMU5Hi7zKex9hBDReBrA==
=93j9
-----END PGP PUBLIC KEY BLOCK-----
89 changes: 78 additions & 11 deletions container/bin/build_source
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
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
export DEB_BUILD_OPTIONS="$build_options"
Expand Down Expand Up @@ -83,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)
Expand All @@ -102,8 +104,8 @@ apt_source() (

git_source() (
IFS='#' read -r url ref <<< "$1"
git clone --bare --branch "$ref" --depth 1 "$url" src.git
GIT_DIR=src.git git archive --prefix src/ "$ref" > 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
)
Expand Down Expand Up @@ -144,35 +146,100 @@ 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"
fi
)

get_sources() (
local source=$1
local source_type=$1

# What kind of source do we have?
if [[ "$source" = "git+"* ]]; then
# What kind of source type do we have?
if [[ "$source_type" = "git+"* ]]; then
git_source "${source#git+}"
elif [[ "$source" = "native" ]]; then
elif [[ "$source_type" = "native" ]]; then
native_source
else
apt_source "$source"
apt_source "$source_type"
fi
)

get_git_tag() (
local tag
if [ -z $PACKAGE_VERSION ]; then
tag=$(get_latest_git_tag)
else
tag=$(get_git_tag_by_version ${PACKAGE_VERSION%-0gardenlinux*})
fi
echo $tag
)

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
latest_tag=$(get_latest_git_tag)
upstream_version="$(get_version_by_git_tag $latest_tag)-0"
else
upstream_version=$(dpkg-parsechangelog --show-field Version)
fi

echo $upstream_version
)

get_version() (
local version=$PACKAGE_VERSION

# If version is undefined, let's simply use
# 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 [ -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.
Expand Down
Loading