Skip to content

Build Debian package #379

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

Merged
merged 3 commits into from
Aug 25, 2019
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
45 changes: 45 additions & 0 deletions .github/workflows/package-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Handles packaging Yarn into Debian and RPM packages
on:
push:
branches:
- master
paths:
- "scripts/actions/build-deb/"
- ".github/workflows/package-workflow.yml"
pull_request:
paths:
- "scripts/actions/build-deb/"
- ".github/workflows/package-workflow.yml"

name: "Release Packages"
jobs:
linux-packages:
name: "Linux Packages"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
version: 12.x

- name: 'Install Yarn 1.17.3'
run: |
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn=1.17.3-1 --no-install-recommends

- name: 'Build'
run: |
set -ex
node ./scripts/run-yarn.js build:cli
./scripts/build-dist.sh

- name: 'Build packages'
uses: ./scripts/actions/build-deb

- name: 'Upload packages'
uses: actions/upload-artifact@master
with:
name: packages
path: artifacts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ junit.xml

# The artifacts generated by "yarn release:all" are never kept
/artifacts
/dist

# This is the Yarn build state; it's local to each clone
/.yarn/build-state.yml
Expand Down
24 changes: 24 additions & 0 deletions scripts/actions/build-deb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:10

LABEL "com.github.actions.name"="build-deb"
LABEL "com.github.actions.description"="Builds the Yarn Debian and RPM packages"
LABEL "com.github.actions.icon"="package"
LABEL "com.github.actions.color"="blue"

# Debian packages
RUN apt-get -y update && \
apt-get install -y --no-install-recommends \
Copy link
Member Author

Choose a reason for hiding this comment

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

fakeroot \
lintian \
rpm \
ruby \
ruby-dev \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Ruby packages
RUN gem install fpm

ADD build-deb.sh /build-deb.sh
ENTRYPOINT ["/build-deb.sh"]
70 changes: 70 additions & 0 deletions scripts/actions/build-deb/build-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash
Copy link
Member Author

Choose a reason for hiding this comment

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


set -ex

# Ensure all the tools we need are available
ensureAvailable() {
command -v "$1" >/dev/null 2>&1 || (echo "You need to install $1" && exit 2)
}
ensureAvailable dpkg-deb
ensureAvailable fpm
ensureAvailable fakeroot
ensureAvailable lintian
ensureAvailable rpmbuild

CONTENTS_DIR=./scripts/actions/build-deb/contents
PACKAGE_TMPDIR=tmp/debian_pkg
VERSION=`./dist/bin/yarn --version`
OUTPUT_DIR=artifacts
DEB_PACKAGE_NAME=yarn-next_$VERSION'_all.deb'

mkdir -p $OUTPUT_DIR
# Remove old packages
rm -f $OUTPUT_DIR/*.deb $OUTPUT_DIR/*.rpm

# Create temporary directory to start building up the package
rm -rf $PACKAGE_TMPDIR
mkdir -p $PACKAGE_TMPDIR/
umask 0022 # Ensure permissions are correct (0755 for dirs, 0644 for files)
PACKAGE_TMPDIR_ABSOLUTE=$(readlink -f $PACKAGE_TMPDIR)

# Create Linux package structure
mkdir -p $PACKAGE_TMPDIR/usr/share/yarn-next/
mkdir -p $PACKAGE_TMPDIR/usr/share/doc/yarn-next/
cp -r dist/* $PACKAGE_TMPDIR/usr/share/yarn-next/
cp $CONTENTS_DIR/copyright $PACKAGE_TMPDIR/usr/share/doc/yarn-next/copyright
chmod 0755 $PACKAGE_TMPDIR/usr/share/yarn-next/

# The Yarn executable expects to be in the same directory as the libraries, so
# we can't just copy it directly to /usr/bin. Symlink them instead.
mkdir -p $PACKAGE_TMPDIR/usr/bin/
ln -s ../share/yarn-next/bin/yarn $PACKAGE_TMPDIR/usr/bin/yarn-next
# Alias as "yarnpkg" too.
ln -s ../share/yarn-next/bin/yarn $PACKAGE_TMPDIR/usr/bin/yarnpkg-next

# Common FPM parameters for all packages we'll build using FPM
FPM="fpm --input-type dir --chdir $PACKAGE_TMPDIR --name yarn-next --version $VERSION "`
`"--vendor 'Yarn Contributors <[email protected]>' --maintainer 'Yarn Contributors <[email protected]>' "`
`"--url https://yarnpkg.com/ --license BSD --description '$(cat $CONTENTS_DIR/description)'"

##### Build RPM (CentOS, Fedora) package
#./scripts/update-dist-manifest.js $PACKAGE_TMPDIR_ABSOLUTE/usr/share/yarn/package.json rpm
eval "$FPM --output-type rpm --architecture noarch --category 'Development/Languages' ."
mv *.rpm $OUTPUT_DIR

##### Build DEB (Debian, Ubuntu) package
#./scripts/update-dist-manifest.js $PACKAGE_TMPDIR_ABSOLUTE/usr/share/yarn/package.json deb
mkdir -p $PACKAGE_TMPDIR/DEBIAN
mkdir -p $PACKAGE_TMPDIR/usr/share/lintian/overrides/
cp $CONTENTS_DIR/lintian-overrides $PACKAGE_TMPDIR/usr/share/lintian/overrides/yarn-next

# Replace variables in Debian package control file
INSTALLED_SIZE=`du -sk $PACKAGE_TMPDIR | cut -f 1`
sed -e "s/\$VERSION/$VERSION/;s/\$INSTALLED_SIZE/$INSTALLED_SIZE/" < $CONTENTS_DIR/control.in > $PACKAGE_TMPDIR/DEBIAN/control
fakeroot dpkg-deb -b $PACKAGE_TMPDIR $DEB_PACKAGE_NAME
mv $DEB_PACKAGE_NAME $OUTPUT_DIR

rm -rf $PACKAGE_TMPDIR

# Lint the Debian package to ensure we're not doing something silly
lintian $OUTPUT_DIR/$DEB_PACKAGE_NAME
23 changes: 23 additions & 0 deletions scripts/actions/build-deb/contents/control.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Package: yarn-next
Version: $VERSION-1
Recommends: nodejs
Conflicts: nodejs (<< 4.0.0), cmdtest
Section: devel
Priority: optional
Architecture: all
Installed-Size: $INSTALLED_SIZE
Maintainer: Yarn Developers <[email protected]>
Homepage: https://yarnpkg.com/
Description: Fast, reliable, and secure dependency management.
Yarn: Fast, reliable, and secure dependency management.
.
Fast: Yarn caches every package it downloads so it never needs to again. It
also parallelizes operations to maximize resource utilization so install times
are faster than ever.
.
Reliable: Using a detailed, but concise, lockfile format, and a deterministic
algorithm for installs, Yarn is able to guarantee that an install that worked
on one system will work exactly the same way on any other system.
.
Secure: Yarn uses checksums to verify the integrity of every installed package
before its code is executed.
8 changes: 8 additions & 0 deletions scripts/actions/build-deb/contents/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Yarn
Upstream-Contact: Yarn Developers <[email protected]>
Source: http://yarnpkg.com/

Files: *
Copyright: 2016-present, Yarn Contributors
License: BSD-2-clause
13 changes: 13 additions & 0 deletions scripts/actions/build-deb/contents/description
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Fast, reliable, and secure dependency management.
Yarn: Fast, reliable, and secure dependency management.

Fast: Yarn caches every package it downloads so it never needs to again. It also
parallelizes operations to maximize resource utilization so install times are
faster than ever.

Reliable: Using a detailed, but concise, lockfile format, and a deterministic
algorithm for installs, Yarn is able to guarantee that an install that worked
on one system will work exactly the same way on any other system.

Secure: Yarn uses checksums to verify the integrity of every installed package
before its code is executed.
4 changes: 4 additions & 0 deletions scripts/actions/build-deb/contents/lintian-overrides
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# No changelog file at the moment
yarn-next: debian-changelog-file-missing
# No manpage... yet!
yarn-next: binary-without-manpage
Copy link
Member Author

Choose a reason for hiding this comment

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

Copied directly from yarn v1. Need to double check if all of these are still needed - A lot of them were due to node_modules junk.

Copy link
Member

Choose a reason for hiding this comment

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

Were those tags meant to describe the yarn package itself, or what it installed? We didn't have a node_modules in the deb file, right? 🤔

Copy link
Member Author

@Daniel15 Daniel15 Aug 23, 2019

Choose a reason for hiding this comment

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

@arcanis - lintian is a linter for Debian packages, and this is a list of the ignored lint rules for the resulting package. These overrides were added before we included a bundle in the Debian package, so many are outdated now.

36 changes: 36 additions & 0 deletions scripts/build-dist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set -Exu
set -o pipefail
# Builds the release tarball for Yarn.

umask 0022 # Ensure permissions are correct (0755 for dirs, 0644 for files)

version=$(yarn --version)

rm -rf dist
mkdir -p artifacts
mkdir -p dist/bin

cp README.md dist/
cp LICENSE.md dist/
cp packages/berry-cli/bundles/berry.js dist/bin/yarn.js
cp scripts/dist-scripts/yarn dist/bin/yarn
cp scripts/dist-scripts/yarn.cmd dist/bin/yarn.cmd
cp scripts/dist-scripts/yarn.ps1 dist/bin/yarn.ps1
# Create yarnpkg as symlink to yarn
ln -s yarn dist/bin/yarnpkg
# Ensure all scripts are executable
chmod +x dist/bin/*

case "$(tar --version)" in
*GNU*)
tar -cvzf artifacts/yarn-next-v$version.tar.gz --transform="s/^dist/yarn-next-v$version/" dist/*
;;
bsdtar*)
tar -cvzf artifacts/yarn-next-v$version.tar.gz -s "/^dist/yarn-next-v$version/" dist/*
;;
*)
echo "Can't determine tar type (BSD/GNU)!"
exit 1
;;
esac
35 changes: 35 additions & 0 deletions scripts/dist-scripts/yarn
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
argv0=$(echo "$0" | sed -e 's,\\,/,g')
basedir=$(dirname "$(readlink "$0" || echo "$argv0")")

case "$(uname -s)" in
Darwin) basedir="$( cd "$( dirname "$argv0" )" && pwd )";;
Linux) basedir=$(dirname "$(readlink -f "$0" || echo "$argv0")");;
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac

command_exists() {
command -v "$1" >/dev/null 2>&1;
}

if command_exists node; then
if [ "$YARN_FORCE_WINPTY" = 1 ] || command_exists winpty && test -t 1; then
winpty node "$basedir/yarn.js" "$@"
else
exec node "$basedir/yarn.js" "$@"
fi
ret=$?
# Debian and Ubuntu use "nodejs" as the name of the binary, not "node", so we
# search for that too. See:
# https://lists.debian.org/debian-devel-announce/2012/07/msg00002.html
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=614907
elif command_exists nodejs; then
exec nodejs "$basedir/yarn.js" "$@"
ret=$?
else
>&2 echo 'Yarn requires Node.js 4.0 or higher to be installed.'
ret=1
fi

exit $ret
2 changes: 2 additions & 0 deletions scripts/dist-scripts/yarn.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
node "%~dp0\yarn.js" %*
6 changes: 6 additions & 0 deletions scripts/dist-scripts/yarn.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function Get-ScriptDirectory {
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}

node "$(Get-ScriptDirectory)/yarn.js" $args