Skip to content

Commit

Permalink
Merge branch 'ubuntu-metadata'
Browse files Browse the repository at this point in the history
  • Loading branch information
rootmos committed Oct 25, 2022
2 parents 7999442 + 8e287e0 commit da8f3c7
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
tee -a /etc/sudoers.d/$UNPRIVILEGED <<< "$UNPRIVILEGED ALL = NOPASSWD: $(which pacman)"
- name: Create PKGBUILD
run: build/archlinux/mk
run: sudo -u $UNPRIVILEGED build/archlinux/mk

- name: Archive PKGBUILD
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION_MAJOR=0
VERSION_MINOR=5
VERSION_PATCH=2
VERSION_PATCH=3
12 changes: 7 additions & 5 deletions build/archlinux/PKGBUILD.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ ROOT=$pkgname-$BUILD_GIT_REF

prepare() {
cat <<EOF > "$ROOT/.build.env"
GIT_REPO=$BUILD_GIT_REPO
GIT_REF=$BUILD_GIT_REF
REPO_URL=$BUILD_REPO_URL
GIT_DIRTY=$BUILD_GIT_DIRTY
SOURCE_TARBALL_URL=$BUILD_SOURCE_TARBALL_URL
GIT_REPO="$BUILD_GIT_REPO"
GIT_REF="$BUILD_GIT_REF"
REPO_URL="$BUILD_REPO_URL"
GIT_DIRTY="$BUILD_GIT_DIRTY"
GIT_USER_NAME="$BUILD_GIT_USER_NAME"
GIT_USER_EMAIL="$BUILD_GIT_USER_EMAIL"
SOURCE_TARBALL_URL="$BUILD_SOURCE_TARBALL_URL"
EOF
}

Expand Down
1 change: 1 addition & 0 deletions build/archlinux/mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SOURCE_TARBALL_SHA256=$(sha256sum "$SOURCE_TARBALL" | cut -f1 -d' ')

VARS=(BUILD_PROJECT BUILD_VERSION)
VARS+=(BUILD_GIT_REPO BUILD_GIT_REF BUILD_REPO_URL BUILD_GIT_DIRTY)
VARS+=(BUILD_GIT_USER_NAME BUILD_GIT_USER_EMAIL)
VARS+=(BUILD_SOURCE_TARBALL_URL SOURCE_TARBALL_SHA256)

export "${VARS[@]}"
Expand Down
4 changes: 2 additions & 2 deletions build/ubuntu/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$PROJECT_NAME ($BUILD_VERSION-1) UNRELEASED; urgency=medium

* Hello Ubuntu!
* Initial packaging of $BUILD_VERSION ($BUILD_GIT_REF)

-- root <root@unknown> Wed, 19 Oct 2022 10:22:30 +0000
-- $BUILD_GIT_USER_NAME <$BUILD_GIT_USER_EMAIL> $BUILD_TIME_RFC5322
6 changes: 3 additions & 3 deletions build/ubuntu/debian/control
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Source: $PROJECT_NAME
Section: unknown
Priority: optional
Maintainer: root <root@unknown>
Maintainer: $BUILD_GIT_USER_NAME <$BUILD_GIT_USER_EMAIL>
Build-Depends: debhelper-compat (= 13), $BUILD_DEPS
Standards-Version: 4.6.0
Homepage: <insert the upstream URL, if relevant>
Homepage: $BUILD_REPO_URL
Rules-Requires-Root: no

Package: $PROJECT_NAME
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, $RUNTIME_DEPS
Description: <insert up to 60 chars description>
Description: Unprivileged sandboxing of popular script languages
4 changes: 3 additions & 1 deletion build/ubuntu/mk
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ BUILD_DEPS=$($SCRIPT_DIR/deps -bc | sed 's/ /, /g')
FILES=(control changelog rules missing-deps)
VARS=(PROJECT_NAME BUILD_VERSION)
VARS+=(RUNTIME_DEPS BUILD_DEPS)
VARS+=(BUILD_GIT_REF BUILD_TIME_RFC5322 BUILD_REPO_URL)
VARS+=(BUILD_GIT_USER_NAME BUILD_GIT_USER_EMAIL)
export "${VARS[@]}"

SH_VARS=""
for v in "${VARS[@]}"; do
SH_VARS="$SH_VARS"'$'"$v"
done
for f in "${FILES[@]}"; do
envsubst "${SH_VARS[@]}" < "$DEBIAN_SRC/$f" > "$DEBIAN_DST/$f"
envsubst "${SH_VARS[@]}" <"$DEBIAN_SRC/$f" >"$DEBIAN_DST/$f"
if [ -x "$DEBIAN_SRC/$f" ]; then
chmod +x "$DEBIAN_DST/$f"
fi
Expand Down
12 changes: 7 additions & 5 deletions tools/archive
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ TMP=$(mktemp -d)
trap 'rm -rf $TMP' EXIT

cat <<EOF > "$TMP/.build.env"
GIT_REPO=$BUILD_GIT_REPO
GIT_REF=$BUILD_GIT_REF
REPO_URL=$BUILD_REPO_URL
GIT_DIRTY=$BUILD_GIT_DIRTY
SOURCE_TARBALL_URL=$BUILD_SOURCE_TARBALL_URL
GIT_REPO="$BUILD_GIT_REPO"
GIT_REF="$BUILD_GIT_REF"
REPO_URL="$BUILD_REPO_URL"
GIT_DIRTY="$BUILD_GIT_DIRTY"
GIT_USER_NAME="$BUILD_GIT_USER_NAME"
GIT_USER_EMAIL="$BUILD_GIT_USER_EMAIL"
SOURCE_TARBALL_URL="$BUILD_SOURCE_TARBALL_URL"
EOF

(
Expand Down
27 changes: 17 additions & 10 deletions tools/build-info
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -o nounset -o pipefail -o errexit

SCRIPT_DIR=$(readlink -f "$0" | xargs dirname)
ROOT=${ROOT-$SCRIPT_DIR/..}
ROOT=${ROOT-$(readlink -f "$SCRIPT_DIR/..")}
VERSION_FILE=${VERSION_FILE-$ROOT/.version}

STYLE=env
Expand All @@ -29,7 +29,7 @@ out() {
kv() {
if [ "$STYLE" = "env" ]; then
out <<EOF
$PREFIX$1=$2
$PREFIX$1="$2"
EOF
elif [ "$STYLE" = "c" ]; then
out <<EOF
Expand All @@ -49,17 +49,20 @@ kv "VERSION" "$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH"

if [ -f "$ROOT/.build.env" ]; then
. "$ROOT/.build.env"
elif [ -n "${CI-}" ]; then
GIT_REF=$GITHUB_SHA
GIT_DIRTY= # HACK: assumption
GIT_REPO=$GITHUB_REPOSITORY
REPO_URL=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY
SOURCE_TARBALL_URL=$REPO_URL/archive/$GIT_REF$TARBALL_SUFFIX
elif command -v git > /dev/null \
&& git rev-parse --show-toplevel >/dev/null 2>&1; then
elif command -v git >/dev/null \
&& git -C "$ROOT" rev-parse --show-toplevel >/dev/null 2>&1; then
cd "$ROOT"
GIT_REF=$(git rev-parse HEAD)
GIT_DIRTY=$([ -n "$(git status --porcelain)" ] && echo "1" || echo)

if [ -n "$GIT_DIRTY" ]; then
GIT_USER_NAME=$(git config user.name)
GIT_USER_EMAIL=$(git config user.email)
else
GIT_USER_NAME=$(git --no-pager log --format=format:'%an' -n 1)
GIT_USER_EMAIL=$(git --no-pager log --format=format:'%ae' -n 1)
fi

ORIGIN=$(git remote get-url origin)
DOMAIN=github.com
if grep -cq "^git@$DOMAIN:" <<< "$ORIGIN"; then
Expand Down Expand Up @@ -87,3 +90,7 @@ kv "REPO_URL" "$REPO_URL"
kv "SOURCE_TARBALL_URL" "$SOURCE_TARBALL_URL"

kv "TIME" "$(date -Is)"
kv "TIME_RFC5322" "$(date --rfc-email)"

kv "GIT_USER_NAME" "$GIT_USER_NAME"
kv "GIT_USER_EMAIL" "$GIT_USER_EMAIL"

0 comments on commit da8f3c7

Please sign in to comment.