Skip to content

Commit

Permalink
Merge pull request #164 from kyle-rader/user/kyrader/linux-installer
Browse files Browse the repository at this point in the history
Add a Linux .deb installer CI workflow
  • Loading branch information
Kyle W. Rader authored Sep 14, 2020
2 parents 1ceeb7b + 3e56e9a commit f93dee0
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 152 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build-installers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build-Installers

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
linux:
name: "Linux"

runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Indicate full history so Nerdbank.GitVersioning works.

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.302

- name: Install dependencies
run: dotnet restore --force

- name: Build Linux Payloads
run: dotnet build -c release src/linux/Payload.Linux/Payload.Linux.csproj

- name: Upload Installers
uses: actions/upload-artifact@v2
with:
name: Installers
path: |
out/linux/*.deb
out/linux/*.tar.gz
123 changes: 109 additions & 14 deletions src/linux/Payload.Linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ die () {
exit 1
}

echo "Building Payload.Linux..."
make_absolute () {
case "$1" in
/*)
echo "$1"
;;
*)
echo "$PWD/$1"
;;
esac
}

# Directories
THISDIR="$( cd "$(dirname "$0")" ; pwd -P )"
ROOT="$( cd "$THISDIR"/../../.. ; pwd -P )"
SRC="$ROOT/src"
OUT="$ROOT/out"
PAYLOAD_SRC="$SRC/linux/Payload.Linux"
PAYLOAD_OUT="$OUT/linux/Payload.Linux"
#####################################################################
# Building
#####################################################################
echo "Building Payload.Linux..."

# Parse script arguments
for i in "$@"
Expand All @@ -32,17 +38,106 @@ case "$i" in
esac
done

# Directories
THISDIR="$( cd "$(dirname "$0")" ; pwd -P )"
ROOT="$( cd "$THISDIR"/../../.. ; pwd -P )"
SRC="$ROOT/src"
OUT="$ROOT/out"
GCM_SRC="$SRC/shared/Git-Credential-Manager"
PAYLOAD_OUT="$OUT/linux/"

# Build parameters
FRAMEWORK=netcoreapp3.1
RUNTIME=linux-x64

# Perform pre-execution checks
CONFIGURATION="${CONFIGURATION:=Debug}"
if [ -z "$VERSION" ]; then
die "--version was not set"
fi

PAYLOAD="$PAYLOAD_OUT/tar/$CONFIGURATION/payload"
TAROUT="$PAYLOAD_OUT/tar/$CONFIGURATION/gcmcore-linux-x86_64-$VERSION.tar.gz"
ARCH="`dpkg-architecture -q DEB_HOST_ARCH`"
if test -z "$ARCH"; then
die "Could not determine host architecture!"
fi

# Outputs
PAYLOAD="$PAYLOAD_OUT/payload/$CONFIGURATION"
TAROUT="$PAYLOAD_OUT/gcmcore-linux_$ARCH.$CONFIGURATION.$VERSION.tar.gz"
DEBPKG="$PAYLOAD_OUT/gcmcore-linux/"
DEBOUT="$PAYLOAD_OUT/gcmcore-linux_$ARCH.$CONFIGURATION.$VERSION.deb"
SYMBOLOUT="$PAYLOAD.sym"

# Cleanup payload directory
if [ -d "$PAYLOAD" ]; then
echo "Cleaning existing payload directory '$PAYLOAD'..."
rm -rf "$PAYLOAD"
fi

# Ensure directories exists
mkdir -p "$PAYLOAD" "$SYMBOLOUT" "$DEBPKG"

# Publish core application executables
echo "Publishing core application..."
dotnet publish "$GCM_SRC" \
--configuration="$CONFIGURATION" \
--framework="$FRAMEWORK" \
--runtime="$RUNTIME" \
--self-contained=true \
"/p:PublishSingleFile=True" \
--output="$(make_absolute "$PAYLOAD")" || exit 1

# Collect symbols
echo "Collecting managed symbols..."
mv "$PAYLOAD"/*.pdb "$SYMBOLOUT" || exit 1

echo "Build complete."

#####################################################################
# PACKING
#####################################################################
echo "Packing Payload.Linux..."
# Cleanup any old archive files
if [ -e "$TAROUT" ]; then
echo "Deleteing old archive '$TAROUT'..."
rm "$TAROUT"
fi

# Ensure the parent directory for the archive exists
mkdir -p "$(dirname "$TAROUT")"

# Set full read, write, execute permissions for owner and just read and execute permissions for group and other
echo "Setting file permissions..."
/bin/chmod -R 755 "$PAYLOAD" || exit 1

# Build tarball
echo "Building archive..."
pushd "$PAYLOAD"
tar -czvf "$TAROUT" * || exit 1
popd

# Build .deb
INSTALL_TO="$DEBPKG/usr/bin/"
mkdir -p "$DEBPKG/DEBIAN" "$INSTALL_TO"

# make the debian control file
cat >"$DEBPKG/DEBIAN/control" <<EOF
Package: gcmcore
Version: $VERSION
Section: vcs
Priority: optional
Architecture: $ARCH
Depends:
Maintainer: GCM-Core <gcmcore@microsoft.com>
Description: Cross Platform Git-Credential-Manager-Core command line utility.
Linux build of the GCM-Core project to support auth with a number of
git hosting providers including GitHub, BitBucket, and Azure DevOps.
Hosted at https://github.com/microsoft/Git-Credential-Manager-Core
EOF

# Copy single binary to target installation location
cp "$PAYLOAD/git-credential-manager-core" "$INSTALL_TO"

# Layout and pack
"$PAYLOAD_SRC/layout.sh" --configuration="$CONFIGURATION" --output="$PAYLOAD" || exit 1
"$PAYLOAD_SRC/pack.sh" --payload="$PAYLOAD" --output="$TAROUT" || exit 1
dpkg-deb --build "$DEBPKG" "$DEBOUT"

echo "Build of Payload.Linux complete."
echo "Pack complete."
79 changes: 0 additions & 79 deletions src/linux/Payload.Linux/layout.sh

This file was deleted.

59 changes: 0 additions & 59 deletions src/linux/Payload.Linux/pack.sh

This file was deleted.

0 comments on commit f93dee0

Please sign in to comment.