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

Split release creation from actual package build #28

Merged
merged 1 commit into from
Nov 29, 2023
Merged
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
Split release creation from actual package build
  • Loading branch information
nanory committed Nov 29, 2023
commit 7aa7f0e3fa34a91c84e2062ff47886bb0b5ffe2d
110 changes: 69 additions & 41 deletions .github/workflows/build_pkg.yml
Original file line number Diff line number Diff line change
@@ -37,10 +37,11 @@ jobs:
name: source package
outputs:
pkg: ${{ steps.build.outputs.pkg }}
source_name: ${{ steps.build.outputs.source_name }}
source_version: ${{ steps.build.outputs.source_version }}
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:
@@ -51,6 +52,8 @@ jobs:
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
path: input
fetch-tags: true
fetch-depth: 0
- name: pull build container
run: podman pull "${{ inputs.build_container }}:amd64"
- name: fetch dependencies
@@ -84,30 +87,18 @@ jobs:
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: |
if ./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" exists "${{ steps.build.outputs.pkg }}"; then
echo "skip_release=true" | tee "$GITHUB_OUTPUT"
else
echo "skip_release=false" | tee "$GITHUB_OUTPUT"
fi
- name: draft release and upload source packages
id: release
if: ${{ steps.check.outputs.skip_release != 'true' }}
env:
PKG_NAME: ${{ steps.build.outputs.pkg }}
run: |
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
echo "release=$release" | tee "$GITHUB_OUTPUT"
echo "source_version=$(cat output/.source_version)" | tee -a "$GITHUB_OUTPUT"
- name: upload source packages
uses: actions/upload-artifact@v3
with:
name: source
path: |
output/
!output/.*
retention-days: 7
packages:
name: ${{ matrix.target == 'indep' && 'architecture independent packages' || format('{0} binary packages', matrix.arch) }}
needs: source
if: ${{ needs.source.outputs.release != '' }}
runs-on: ubuntu-latest
strategy:
matrix:
@@ -125,18 +116,16 @@ jobs:
run: sudo podman run --privileged ghcr.io/gardenlinux/binfmt_container
- name: pull build container
run: podman pull "${{ inputs.build_container }}:${{ matrix.arch }}"
- name: get source package
- name: get source packages
uses: actions/download-artifact@v3
with:
name: source
path: input/
- name: prepare source package for build
run: |
mkdir input
cd input
pkg="${{ needs.source.outputs.pkg }}"
release="${{ needs.source.outputs.release }}"
../scripts/gh_release "${{ github.token }}" "${{ github.repository }}" download "$release" "$pkg.dsc"
awk '!/^ / { flag=0 } flag { print $NF } /^Files:/ { flag=1 }' < "$pkg.dsc" | while read -r file; do
../scripts/gh_release "${{ github.token }}" "${{ github.repository }}" download "$release" "$file"
done
cd input/
echo "${{ needs.source.outputs.build_options }}" > .build_options
ln -s "$pkg.dsc" .source
ln -s "${{ needs.source.outputs.pkg }}.dsc" .source
- name: fetch dependencies
run: |
mkdir _pkgs
@@ -162,23 +151,62 @@ jobs:
"build_${{ matrix.target }}"
)"
echo "pkg=$pkg" | tee -a "$GITHUB_OUTPUT"
- name: upload packages
if: ${{ steps.build.outputs.pkg != '' }}
run: |
release="${{ needs.source.outputs.release }}"
for f in output/*; do
./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" upload "$release" "$f"
done
- name: upload binary packages
uses: actions/upload-artifact@v3
with:
name: binary
path: |
output/
!output/.*
retention-days: 7
publish:
needs: [ source, packages ]
if: ${{ needs.source.outputs.release != '' }}
# Only publish packages, if the build has been triggered by a Git Tag (e.g gardenlinux/1.0.0gardenlinux1)
# or if the build package contains the gardenlinux0 suffix which it will get if there has not been a
# version released already for the given upstream version. Then, the pipeline automatically assignes this package
# to the gardenlinux0 release of the package.
if: |
contains(github.ref, format('refs/tags/gardenlinux/{0}', needs.source.outputs.source_version)) ||
endsWith(needs.source.outputs.source_version, 'gardenlinux0')
env:
RELEASE_GIT_TAG: ${{ format('gardenlinux/{0}', needs.source.outputs.source_version) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: gardenlinux/package-build
- name: check if ${{ env.pkg }} already released
id: check
run: |
if ./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" exists "${{ needs.source.outputs.pkg }}"; then
echo "skip_release=true" | tee "$GITHUB_OUTPUT"
else
echo "skip_release=false" | tee "$GITHUB_OUTPUT"
fi
- name: download source packages
if: ${{ steps.check.outputs.skip_release != 'true' }}
uses: actions/download-artifact@v3
with:
name: source
path: output/
- name: download binary packages
if: ${{ steps.check.outputs.skip_release != 'true' }}
uses: actions/download-artifact@v3
with:
name: binary
path: output/
- name: draft release and upload packages
id: release
if: ${{ steps.check.outputs.skip_release != 'true' }}
run: |
release="$(./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" create --draft "$RELEASE_GIT_TAG" "${{ github.sha }}" "${{ needs.source.outputs.pkg }}")"
for f in output/*; do
./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" upload "$release" "$f"
done
echo "release=$release" | tee "$GITHUB_OUTPUT"
- name: publish drafted release
run: ./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" publish_draft "${{ needs.source.outputs.release }}"
if: ${{ steps.check.outputs.skip_release != 'true' }}
run: ./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" publish_draft "${{ steps.release.outputs.release }}"
cleanup:
needs: [ source, packages ]
if: ${{ always() && contains(needs.*.result, 'failure') }}
21 changes: 17 additions & 4 deletions container/bin/build_source
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@ main() (
# Define Build Options
export DEB_BUILD_OPTIONS="$build_options"

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

# Get sources for building source package
# out of it
get_sources $source
@@ -62,11 +65,12 @@ main() (
# Add some meta files next to the created artifacts
echo "$DEB_BUILD_OPTIONS" > .build_options
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; echo "${pkg}_${version}.dsc"; get_files < "${pkg}_${version}.dsc"; } | while read file; do
{ echo .build_options; 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
@@ -160,12 +164,21 @@ get_sources() (
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)"
if [ -z "$version" ]; then
package_version=$(dpkg-parsechangelog --show-field Version)
commit_hash=$(git -C /input rev-parse HEAD)

# 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 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
echo $version