Skip to content

Commit f533868

Browse files
Daniel15arcanis
authored andcommitted
Build Debian package (#379)
* [WIP] Build Debian package * Move to a separate workflow * Include shell, batch and PowerShell Yarn scripts
1 parent 462a0fd commit f533868

File tree

12 files changed

+267
-0
lines changed

12 files changed

+267
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Handles packaging Yarn into Debian and RPM packages
2+
on:
3+
push:
4+
branches:
5+
- master
6+
paths:
7+
- "scripts/actions/build-deb/"
8+
- ".github/workflows/package-workflow.yml"
9+
pull_request:
10+
paths:
11+
- "scripts/actions/build-deb/"
12+
- ".github/workflows/package-workflow.yml"
13+
14+
name: "Release Packages"
15+
jobs:
16+
linux-packages:
17+
name: "Linux Packages"
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@master
22+
- uses: actions/setup-node@master
23+
with:
24+
version: 12.x
25+
26+
- name: 'Install Yarn 1.17.3'
27+
run: |
28+
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
29+
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
30+
sudo apt-get update && sudo apt-get install yarn=1.17.3-1 --no-install-recommends
31+
32+
- name: 'Build'
33+
run: |
34+
set -ex
35+
node ./scripts/run-yarn.js build:cli
36+
./scripts/build-dist.sh
37+
38+
- name: 'Build packages'
39+
uses: ./scripts/actions/build-deb
40+
41+
- name: 'Upload packages'
42+
uses: actions/upload-artifact@master
43+
with:
44+
name: packages
45+
path: artifacts

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ junit.xml
77

88
# The artifacts generated by "yarn release:all" are never kept
99
/artifacts
10+
/dist
1011

1112
# This is the Yarn build state; it's local to each clone
1213
/.yarn/build-state.yml

scripts/actions/build-deb/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM node:10
2+
3+
LABEL "com.github.actions.name"="build-deb"
4+
LABEL "com.github.actions.description"="Builds the Yarn Debian and RPM packages"
5+
LABEL "com.github.actions.icon"="package"
6+
LABEL "com.github.actions.color"="blue"
7+
8+
# Debian packages
9+
RUN apt-get -y update && \
10+
apt-get install -y --no-install-recommends \
11+
fakeroot \
12+
lintian \
13+
rpm \
14+
ruby \
15+
ruby-dev \
16+
&& \
17+
apt-get clean && \
18+
rm -rf /var/lib/apt/lists/*
19+
20+
# Ruby packages
21+
RUN gem install fpm
22+
23+
ADD build-deb.sh /build-deb.sh
24+
ENTRYPOINT ["/build-deb.sh"]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
# Ensure all the tools we need are available
6+
ensureAvailable() {
7+
command -v "$1" >/dev/null 2>&1 || (echo "You need to install $1" && exit 2)
8+
}
9+
ensureAvailable dpkg-deb
10+
ensureAvailable fpm
11+
ensureAvailable fakeroot
12+
ensureAvailable lintian
13+
ensureAvailable rpmbuild
14+
15+
CONTENTS_DIR=./scripts/actions/build-deb/contents
16+
PACKAGE_TMPDIR=tmp/debian_pkg
17+
VERSION=`./dist/bin/yarn --version`
18+
OUTPUT_DIR=artifacts
19+
DEB_PACKAGE_NAME=yarn-next_$VERSION'_all.deb'
20+
21+
mkdir -p $OUTPUT_DIR
22+
# Remove old packages
23+
rm -f $OUTPUT_DIR/*.deb $OUTPUT_DIR/*.rpm
24+
25+
# Create temporary directory to start building up the package
26+
rm -rf $PACKAGE_TMPDIR
27+
mkdir -p $PACKAGE_TMPDIR/
28+
umask 0022 # Ensure permissions are correct (0755 for dirs, 0644 for files)
29+
PACKAGE_TMPDIR_ABSOLUTE=$(readlink -f $PACKAGE_TMPDIR)
30+
31+
# Create Linux package structure
32+
mkdir -p $PACKAGE_TMPDIR/usr/share/yarn-next/
33+
mkdir -p $PACKAGE_TMPDIR/usr/share/doc/yarn-next/
34+
cp -r dist/* $PACKAGE_TMPDIR/usr/share/yarn-next/
35+
cp $CONTENTS_DIR/copyright $PACKAGE_TMPDIR/usr/share/doc/yarn-next/copyright
36+
chmod 0755 $PACKAGE_TMPDIR/usr/share/yarn-next/
37+
38+
# The Yarn executable expects to be in the same directory as the libraries, so
39+
# we can't just copy it directly to /usr/bin. Symlink them instead.
40+
mkdir -p $PACKAGE_TMPDIR/usr/bin/
41+
ln -s ../share/yarn-next/bin/yarn $PACKAGE_TMPDIR/usr/bin/yarn-next
42+
# Alias as "yarnpkg" too.
43+
ln -s ../share/yarn-next/bin/yarn $PACKAGE_TMPDIR/usr/bin/yarnpkg-next
44+
45+
# Common FPM parameters for all packages we'll build using FPM
46+
FPM="fpm --input-type dir --chdir $PACKAGE_TMPDIR --name yarn-next --version $VERSION "`
47+
`"--vendor 'Yarn Contributors <[email protected]>' --maintainer 'Yarn Contributors <[email protected]>' "`
48+
`"--url https://yarnpkg.com/ --license BSD --description '$(cat $CONTENTS_DIR/description)'"
49+
50+
##### Build RPM (CentOS, Fedora) package
51+
#./scripts/update-dist-manifest.js $PACKAGE_TMPDIR_ABSOLUTE/usr/share/yarn/package.json rpm
52+
eval "$FPM --output-type rpm --architecture noarch --category 'Development/Languages' ."
53+
mv *.rpm $OUTPUT_DIR
54+
55+
##### Build DEB (Debian, Ubuntu) package
56+
#./scripts/update-dist-manifest.js $PACKAGE_TMPDIR_ABSOLUTE/usr/share/yarn/package.json deb
57+
mkdir -p $PACKAGE_TMPDIR/DEBIAN
58+
mkdir -p $PACKAGE_TMPDIR/usr/share/lintian/overrides/
59+
cp $CONTENTS_DIR/lintian-overrides $PACKAGE_TMPDIR/usr/share/lintian/overrides/yarn-next
60+
61+
# Replace variables in Debian package control file
62+
INSTALLED_SIZE=`du -sk $PACKAGE_TMPDIR | cut -f 1`
63+
sed -e "s/\$VERSION/$VERSION/;s/\$INSTALLED_SIZE/$INSTALLED_SIZE/" < $CONTENTS_DIR/control.in > $PACKAGE_TMPDIR/DEBIAN/control
64+
fakeroot dpkg-deb -b $PACKAGE_TMPDIR $DEB_PACKAGE_NAME
65+
mv $DEB_PACKAGE_NAME $OUTPUT_DIR
66+
67+
rm -rf $PACKAGE_TMPDIR
68+
69+
# Lint the Debian package to ensure we're not doing something silly
70+
lintian $OUTPUT_DIR/$DEB_PACKAGE_NAME
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Package: yarn-next
2+
Version: $VERSION-1
3+
Recommends: nodejs
4+
Conflicts: nodejs (<< 4.0.0), cmdtest
5+
Section: devel
6+
Priority: optional
7+
Architecture: all
8+
Installed-Size: $INSTALLED_SIZE
9+
Maintainer: Yarn Developers <[email protected]>
10+
Homepage: https://yarnpkg.com/
11+
Description: Fast, reliable, and secure dependency management.
12+
Yarn: Fast, reliable, and secure dependency management.
13+
.
14+
Fast: Yarn caches every package it downloads so it never needs to again. It
15+
also parallelizes operations to maximize resource utilization so install times
16+
are faster than ever.
17+
.
18+
Reliable: Using a detailed, but concise, lockfile format, and a deterministic
19+
algorithm for installs, Yarn is able to guarantee that an install that worked
20+
on one system will work exactly the same way on any other system.
21+
.
22+
Secure: Yarn uses checksums to verify the integrity of every installed package
23+
before its code is executed.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2+
Upstream-Name: Yarn
3+
Upstream-Contact: Yarn Developers <[email protected]>
4+
Source: http://yarnpkg.com/
5+
6+
Files: *
7+
Copyright: 2016-present, Yarn Contributors
8+
License: BSD-2-clause
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Fast, reliable, and secure dependency management.
2+
Yarn: Fast, reliable, and secure dependency management.
3+
4+
Fast: Yarn caches every package it downloads so it never needs to again. It also
5+
parallelizes operations to maximize resource utilization so install times are
6+
faster than ever.
7+
8+
Reliable: Using a detailed, but concise, lockfile format, and a deterministic
9+
algorithm for installs, Yarn is able to guarantee that an install that worked
10+
on one system will work exactly the same way on any other system.
11+
12+
Secure: Yarn uses checksums to verify the integrity of every installed package
13+
before its code is executed.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# No changelog file at the moment
2+
yarn-next: debian-changelog-file-missing
3+
# No manpage... yet!
4+
yarn-next: binary-without-manpage

scripts/build-dist.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
set -Exu
3+
set -o pipefail
4+
# Builds the release tarball for Yarn.
5+
6+
umask 0022 # Ensure permissions are correct (0755 for dirs, 0644 for files)
7+
8+
version=$(yarn --version)
9+
10+
rm -rf dist
11+
mkdir -p artifacts
12+
mkdir -p dist/bin
13+
14+
cp README.md dist/
15+
cp LICENSE.md dist/
16+
cp packages/berry-cli/bundles/berry.js dist/bin/yarn.js
17+
cp scripts/dist-scripts/yarn dist/bin/yarn
18+
cp scripts/dist-scripts/yarn.cmd dist/bin/yarn.cmd
19+
cp scripts/dist-scripts/yarn.ps1 dist/bin/yarn.ps1
20+
# Create yarnpkg as symlink to yarn
21+
ln -s yarn dist/bin/yarnpkg
22+
# Ensure all scripts are executable
23+
chmod +x dist/bin/*
24+
25+
case "$(tar --version)" in
26+
*GNU*)
27+
tar -cvzf artifacts/yarn-next-v$version.tar.gz --transform="s/^dist/yarn-next-v$version/" dist/*
28+
;;
29+
bsdtar*)
30+
tar -cvzf artifacts/yarn-next-v$version.tar.gz -s "/^dist/yarn-next-v$version/" dist/*
31+
;;
32+
*)
33+
echo "Can't determine tar type (BSD/GNU)!"
34+
exit 1
35+
;;
36+
esac

scripts/dist-scripts/yarn

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
argv0=$(echo "$0" | sed -e 's,\\,/,g')
3+
basedir=$(dirname "$(readlink "$0" || echo "$argv0")")
4+
5+
case "$(uname -s)" in
6+
Darwin) basedir="$( cd "$( dirname "$argv0" )" && pwd )";;
7+
Linux) basedir=$(dirname "$(readlink -f "$0" || echo "$argv0")");;
8+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
9+
*MSYS*) basedir=`cygpath -w "$basedir"`;;
10+
esac
11+
12+
command_exists() {
13+
command -v "$1" >/dev/null 2>&1;
14+
}
15+
16+
if command_exists node; then
17+
if [ "$YARN_FORCE_WINPTY" = 1 ] || command_exists winpty && test -t 1; then
18+
winpty node "$basedir/yarn.js" "$@"
19+
else
20+
exec node "$basedir/yarn.js" "$@"
21+
fi
22+
ret=$?
23+
# Debian and Ubuntu use "nodejs" as the name of the binary, not "node", so we
24+
# search for that too. See:
25+
# https://lists.debian.org/debian-devel-announce/2012/07/msg00002.html
26+
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=614907
27+
elif command_exists nodejs; then
28+
exec nodejs "$basedir/yarn.js" "$@"
29+
ret=$?
30+
else
31+
>&2 echo 'Yarn requires Node.js 4.0 or higher to be installed.'
32+
ret=1
33+
fi
34+
35+
exit $ret

scripts/dist-scripts/yarn.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
node "%~dp0\yarn.js" %*

scripts/dist-scripts/yarn.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function Get-ScriptDirectory {
2+
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
3+
Split-Path $Invocation.MyCommand.Path
4+
}
5+
6+
node "$(Get-ScriptDirectory)/yarn.js" $args

0 commit comments

Comments
 (0)