Skip to content

Commit

Permalink
Remove pkg.yml and adjust versioning logic (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanory committed Nov 28, 2023
1 parent bacc01c commit aaf6b65
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 32 deletions.
31 changes: 30 additions & 1 deletion .github/workflows/build_pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,27 @@ on:
build_container:
type: string
default: ghcr.io/gardenlinux/package-build
source:
type: string
default: ""
debian_source:
type: string
default: ""
dependencies:
type: string
default: ""
email:
type: string
default: ""
maintainer:
type: string
default: ""
distribution:
type: string
default: ""
message:
type: string
default: ""
jobs:
source:
name: source package
Expand All @@ -22,6 +40,7 @@ jobs:
build_options: ${{ steps.build.outputs.build_options }}
release: ${{ steps.release.outputs.release }}
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -47,17 +66,24 @@ jobs:
cat _pkgs/Packages
- name: build
id: build
env:
GITHUB_REF_TYPE: ${{ github.ref_type }}
GITHUB_REF_NAME: ${{ github.ref_name }}
run: |
version=""
[ "$GITHUB_REF_TYPE" == "tag" ] && version=${GITHUB_REF_NAME#*/}
pkg="$(podman run \
--rm \
--mount="type=bind,src=$PWD/${GITHUB_ACTION_PATH}/container/bin,dst=/usr/local/sbin,ro" \
-e PACKAGE_VERSION="$version" \
-v "$PWD/input:/input" \
-v "$PWD/output:/output" \
-v "$PWD/_pkgs:/pkgs" \
"${{ inputs.build_container }}:amd64" build_source
)"
echo "pkg=$pkg" | tee -a "$GITHUB_OUTPUT"
echo "build_options=$(cat output/.build_options)" | tee -a "$GITHUB_OUTPUT"
echo "source_name=$(cat output/.source_name)" | tee -a "$GITHUB_OUTPUT"
- name: check if ${{ env.pkg }} already released
id: check
run: |
Expand All @@ -69,8 +95,11 @@ jobs:
- name: draft release and upload source packages
id: release
if: ${{ steps.check.outputs.skip_release != 'true' }}
env:
PKG_NAME: ${{ steps.build.outputs.pkg }}
run: |
release="$(./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" create --draft "${{ steps.build.outputs.pkg }}" "${{ github.sha }}" "${{ steps.build.outputs.pkg }}")"
tag="gardenlinux/${PKG_NAME#${{ steps.build.outputs.source_name }}_}"
release="$(./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" create --draft "$tag" "${{ github.sha }}" "${{ steps.build.outputs.pkg }}")"
for f in output/*; do
./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" upload "$release" "$f"
done
Expand Down
82 changes: 55 additions & 27 deletions container/bin/build_source
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,37 @@ email="[email protected]"
maintainer="Garden Linux Builder"
distribution=gardenlinux
message="Rebuild for Garden Linux."
debian_source=""
inputs_file="/input/.github/workflows/build.yml"

main() (
DEB_BUILD_OPTIONS="terse $(yq -r '.build_options // ""' < "/input/pkg.yaml")"
export DEB_BUILD_OPTIONS
# Init some variables
name="$(yq -r '.name' < "$inputs_file")"
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")"

source="$(yq -r '.source // ""' < "/input/pkg.yaml")"
debian_source="$(yq -r '.debian_source // ""' < "/input/pkg.yaml")"
# Define Build Options
export DEB_BUILD_OPTIONS="$build_options"

if [[ "$source" = "git+"* ]]; then
git_source "${source#git+}"
elif [[ "$source" = "native" ]]; then
native_source
else
apt_source "$source"
fi
# Get sources for building source package
# out of it
get_sources $source

# if debian_source defined: remove debian folder from source and replace with debian folder from debian_source
# Is the debian_source parameter specified?
# If yes, replace the original debian/ directory
# with the one provided via debian_source.
if [ -n "$debian_source" ]; then
mkdir debian_src
cd debian_src
if [[ "$debian_source" = "git+"* ]]; then
git_source "${debian_source#git+}"
else
apt_source "$debian_source"
fi
get_sources $debian_source
rm -rf ../src/debian
mv src/debian ../src/
cd ..
rm -rf debian_src
fi

# Start preparing and building the source package
cd src
apply_patches /input

Expand All @@ -54,20 +53,25 @@ main() (
fi

dpkg-source --build .

cd ..

# Do some cleanup afterwards
rm -rf src
ls -lah

# Add some meta files next to the created artifacts
echo "$DEB_BUILD_OPTIONS" > .build_options
echo "${pkg}" > .source_name
ln -s "${pkg}_${version}.dsc" .source

# Copy all artifacts to the dedicated output directory
if [ -d "/output" ]; then
{ echo .build_options; echo .source; echo "${pkg}_${version}.dsc"; get_files < "${pkg}_${version}.dsc"; } | while read file; do
{ echo .build_options; echo .source_name; echo .source; echo "${pkg}_${version}.dsc"; get_files < "${pkg}_${version}.dsc"; } | while read file; do
sudo cp -d "$file" "/output/$file"
done
fi

# Finally, print the package name and version
echo "${pkg}_${version}" >&3
)

Expand Down Expand Up @@ -128,21 +132,45 @@ apply_patches() (
fi

name="$(yq -r '.name' < "$inputs_file")"
version="$(yq -r '.version // ""' < "$1/pkg.yaml")"
[ -n "$version" ] || version="$(dpkg-parsechangelog --show-field Version)"
email="$(yq -r --arg name "$name" '.jobs[$name].with.email // "'"$email"'"' < "$inputs_file")"
maintainer="$(yq -r --arg name "$name" '.jobs[$name].with.maintainer // "'"$maintainer"'"' < "$inputs_file")"
distribution="$(yq -r --arg name "$name" '.jobs[$name].with.distribution // "'"$distribution"'"' < "$inputs_file")"
version_suffix="$(yq -r '.version_suffix // ""' < "$1/pkg.yaml")"
message="$(yq -r --arg name "$name" '.jobs[$name].with.message // "'"$message"'"' < "$inputs_file")"
email="$(yq -r '.jobs.build_pkg.with.email // "'"$email"'"' < "$inputs_file")"
maintainer="$(yq -r '.jobs.build_pkg.with.maintainer // "'"$maintainer"'"' < "$inputs_file")"
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 "$version$version_suffix" --distribution "$distribution" --force-distribution -- "$message"
DEBEMAIL="$email" DEBFULLNAME="$maintainer" dch --newversion "$(get_version)" --distribution "$distribution" --force-distribution -- "$message"

if [ -x "$1/exec.post" ]; then
SOURCE="$source" "$1/exec.post"
fi
)

get_sources() (
local source=$1

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

get_version() (
local version=$PACKAGE_VERSION

git -C /input config --global --add safe.directory '*'

# If version is undefined, let's simply use
# the version of the upstream package and add
# the git tag to it.
[ -n "$version" ] || version="$(dpkg-parsechangelog --show-field Version)gardenlinux~$(git -C /input rev-parse HEAD)"

# Print the version accordingly
echo $version
)

get_files() (
awk '!/^ / { flag=0 } flag { print $NF } /^Files:/ { flag=1 }'
)
Expand Down
3 changes: 3 additions & 0 deletions container/build.containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ RUN apt-get update \
FROM $arch/$image
WORKDIR /tmp

# Define Environment variables
ENV PACKAGE_VERSION=""

# Copy repository configration files for apt
COPY container/apt/ /etc/apt/

Expand Down
14 changes: 10 additions & 4 deletions scripts/gh_release
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ case "$action" in
commit="$1"; shift
name="$1"; shift

normalized_tag=${tag/\~/\_}

release="$(post "releases" '{
"draft": '"$draft"',
"tag_name": "'"$tag"'",
"tag_name": "'"$normalized_tag"'",
"target_commitish": "'"$commit"'",
"name": "'"$name"'"
}' | jq -r '.id')"
Expand All @@ -78,16 +80,20 @@ case "$action" in
release="$1"; shift
asset_file="$1"; shift

asset_name="$(basename "$asset_file")"
normalized_asset_file=${asset_file/\~/\_}

asset_name="$(basename "$normalized_asset_file")"
upload "releases/$release/assets?name=$asset_name" < "$asset_file" > /dev/null
echo "uploaded $asset_file to $release"
echo "uploaded $asset_file to $release ($asset_name)"

;;
"download")
release="$1"; shift
name="$1"; shift

asset_id="$(get "releases/$release/assets" | jq -r '.[] | select(.name == "'"$name"'") | .id')"
normalized_name=${name/\~/\_}

asset_id="$(get "releases/$release/assets" | jq -r '.[] | select(.name == "'"$normalized_name"'") | .id')"
get_binary "releases/assets/$asset_id" > "$name"

;;
Expand Down

0 comments on commit aaf6b65

Please sign in to comment.