Skip to content

Commit

Permalink
Configure GitHub Actions for snapshot builds
Browse files Browse the repository at this point in the history
  • Loading branch information
th-otto committed Sep 13, 2023
1 parent ff19122 commit 410fb74
Show file tree
Hide file tree
Showing 5 changed files with 317 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Linux build

on:
push:
branches: [ binutils-2_41-mintelf ]
pull_request:
branches: [ binutils-2_41-mintelf ]

jobs:
build:
runs-on: ubuntu-20.04
strategy:
matrix:
cross_tool: [ "m68k-atari-mintelf" ]
steps:
- uses: actions/checkout@v3
- name: Install SSH keys
if: ${{ github.event_name == 'push' }}
env:
SSH_ID: ${{ secrets.SSH_ID }}
run: ./.scripts/install_ssh_id.sh
- name: Setup environment
env:
PROJECT_VERSION: "2.41"
CROSS_TOOL: ${{ matrix.cross_tool }}
run: ./.scripts/setup_env.sh
- name: Install packages
run: |
sudo apt-get update
sudo apt-get install libzstd-dev liblzma-dev zlib1g-dev
- name: build
run: ./.scripts/build.sh
- name: deploy
if: ${{ github.event_name == 'push' }}
env:
COMMITER_NAME: ${{ github.event.commits[0].author.name }}
COMMITER_EMAIL: ${{ github.event.commits[0].author.email }}
run: ./.scripts/deploy.sh
117 changes: 117 additions & 0 deletions .scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash -eux
# -e: Exit immediately if a command exits with a non-zero status.
# -u: Treat unset variables as an error when substituting.
# -x: Display expanded script commands

unset CDPATH
unset LANG LANGUAGE LC_ALL LC_CTYPE LC_TIME LC_NUMERIC LC_COLLATE LC_MONETARY LC_MESSAGES

VERSIONPATCH=-20230911
REVISION="GNU Binutils for MiNT ${VERSIONPATCH#-}"

TARGET=${CROSS_TOOL:-m68k-atari-mintelf}
if test "$TARGET" = m68k-atari-mintelf; then
REVISION="GNU Binutils for MiNT ELF ${VERSIONPATCH#-}"
fi
PREFIX=/usr

TAR=${TAR-tar}
TAR_OPTS=${TAR_OPTS---owner=0 --group=0}
LN_S=ln
BUILD_EXEEXT=
MAKE=make

here=`pwd`
srcdir=`pwd`

host=linux64
if test -d /usr/lib64 -a $host = linux64; then
BUILD_LIBDIR=${PREFIX}/lib64
else
BUILD_LIBDIR=${PREFIX}/lib
fi

enable_plugins=--disable-plugins
enable_lto=--disable-lto

case "${TARGET}" in
*-*-*elf* | *-*-linux* | *-*-darwin*)
enable_lto=--enable-lto
enable_plugins=--enable-plugins
;;
esac

MINT_BUILD_DIR=$here/build

rm -rf "$MINT_BUILD_DIR"
mkdir -p "$MINT_BUILD_DIR"

cd "$MINT_BUILD_DIR"

# Note: gdb is explictly disabled here, because it is not needed for the cross-compiler
../configure \
--target="${TARGET}" \
--prefix="${PREFIX}" \
--libdir="$BUILD_LIBDIR" \
--bindir="${PREFIX}/bin" \
--libexecdir='${libdir}' \
--with-pkgversion="$REVISION" \
--with-bugurl='https://github.com/freemint/m68k-atari-mint-binutils-gdb/issues' \
--with-gcc --with-gnu-as --with-gnu-ld \
--disable-gdb --disable-gdbserver --disable-sim \
--disable-werror \
--disable-threads \
--enable-new-dtags \
--enable-relro \
--enable-default-hash-style=both \
$enable_lto \
$enable_plugins \
--disable-nls \
--with-system-zlib \
--with-system-readline \
--disable-bracketed-paste-default \
--with-sysroot="${PREFIX}/${TARGET}/sys-root"

${MAKE} || exit 1

# INSTALL_DIR is set in setup_env.sh
make DESTDIR="$INSTALL_DIR" install-strip >/dev/null || exit 1

mkdir -p "${INSTALL_DIR}/${PREFIX}/${TARGET}/bin"

cd "${INSTALL_DIR}/${PREFIX}/${TARGET}/bin"

for i in addr2line ar as nm ld ld.bfd objcopy objdump ranlib strip readelf dlltool dllwrap size strings; do
if test -x ../../bin/${TARGET}-$i; then
rm -f ${i} ${i}${BUILD_EXEEXT}
$LN_S ../../bin/${TARGET}-$i${BUILD_EXEEXT} $i
fi
done

cd "${INSTALL_DIR}/${PREFIX}/bin"

rm -f ${TARGET}-ld ${TARGET}-ld${BUILD_EXEEXT}
$LN_S ${TARGET}-ld.bfd${BUILD_EXEEXT} ${TARGET}-ld${BUILD_EXEEXT}
cd "${INSTALL_DIR}" || exit 1

rm -f ${BUILD_LIBDIR#/}/libiberty.a

# do not overwrite the system files
rm -rf ${PREFIX#/}/share/info
rm -rf ${PREFIX#/}/share/man
rm -f ${BUILD_LIBDIR#/}/bfd-plugins/libdep.so
rm -f ${BUILD_LIBDIR#/}/bfd-plugins/*dep.dll
rmdir ${BUILD_LIBDIR#/}/bfd-plugins 2>/dev/null || :
rm -f ${PREFIX#/}/${TARGET}/lib/ldscripts/m68kmintelf.{xbn,xe,xn,xr,xu}

# remove gdb if it was build; we don't need it for the cross compiler
rm -f ${PREFIX#/}/bin/${TARGET}-gdb*
rm -rf "${PREFIX#/}/share/gdb"
rm -rf "${PREFIX#/}/include/gdb"
rm -rf "${PREFIX#/}/include/sim"

# archive is created in deploy.sh
# toolsuffix=${TARGET##*-}
# TARNAME=${PROJECT_NAME}-${PROJECT_VERSION}-${toolsuffix}

# ${TAR} ${TAR_OPTS} -jcf ${DEPLOY_DIR}/${TARNAME}-ubuntu-20.04.tar.bz2 ${PREFIX#/}
84 changes: 84 additions & 0 deletions .scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/sh -x

[email protected]
UPLOAD_DIR=$SERVER:/home/www/snapshots

if [ -z "${DEPLOY_ARCHIVE+x}" ]
then
# zip is default
DEPLOY_ARCHIVE="zip"
fi

toolsuffix=${CROSS_TOOL##*-}

ARCHIVE_NAME="${PROJECT_NAME}-${PROJECT_VERSION}-${SHORT_ID}-${toolsuffix}.${DEPLOY_ARCHIVE}"
ARCHIVE_PATH="${DEPLOY_DIR}/${ARCHIVE_NAME}"

mkdir -p "${DEPLOY_DIR}"

if [ "${DEPLOY_ARCHIVE}" = "tar.bz2" ]
then
cd ${INSTALL_DIR} && tar cjf ${ARCHIVE_PATH} *
elif [ "${DEPLOY_ARCHIVE}" = "tar.xz" ]
then
cd ${INSTALL_DIR} && tar cJf ${ARCHIVE_PATH} *
elif [ "${DEPLOY_ARCHIVE}" = "tar.gz" ]
then
cd ${INSTALL_DIR} && tar czf ${ARCHIVE_PATH} *
else
cd $(dirname ${INSTALL_DIR}) && zip -r -9 ${ARCHIVE_PATH} $(basename ${INSTALL_DIR})
fi

cd -


eval "$(ssh-agent -s)"

PROJECT_DIR="$PROJECT_NAME"
case $PROJECT_DIR in
m68k-atari-mint-gcc) PROJECT_DIR=gcc ;;
m68k-atari-mint-binutils-gdb) PROJECT_DIR=binutils ;;
esac

upload_file() {
local from="$1"
local to="$2"
for i in 1 2 3
do
scp -o "StrictHostKeyChecking no" "$from" "$to"
[ $? = 0 ] && return 0
sleep 1
done
exit 1
}

link_file() {
local from="$1"
local to="$2"
for i in 1 2 3
do
ssh -o "StrictHostKeyChecking no" $SERVER -- "cd www/snapshots/${PROJECT_DIR}; ln -sf $from $to"
[ $? = 0 ] && return 0
sleep 1
done
exit 1
}

upload_file "$ARCHIVE_PATH" "${UPLOAD_DIR}/${PROJECT_DIR}/${ARCHIVE_NAME}"

#
# *-latest links are currently not provided, because we dont
# want to overwrite known-to-work versions that are used for
# other projects with experimental ones
#
#if test -z "${CPU_TARGET}"
#then
# link_file "$ARCHIVE_NAME" "${PROJECT_DIR}-${toolsuffix}-latest.${DEPLOY_ARCHIVE}"
# # traditionally, that link did not contain the cross toolchain suffix
# if test "$toolsuffix" = "mint"; then
# link_file "$ARCHIVE_NAME" "${PROJECT_DIR}-latest.${DEPLOY_ARCHIVE}"
# fi
#fi

echo ${PROJECT_NAME}-${PROJECT_VERSION}-${SHORT_ID} > .latest_version
upload_file .latest_version "${UPLOAD_DIR}/${PROJECT_DIR}/.latest_version"
38 changes: 38 additions & 0 deletions .scripts/install_ssh_id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash -eu
# -e: Exit immediately if a command exits with a non-zero status.
# -u: Treat unset variables as an error when substituting.

# This installs an SSH private/public key pair on the build system,
# so ssh can connect to remote servers without password.
# Important: for passwordless connection to succeed, our public key must be
# manually authorized on the remote server.

# Our private key is the critical security component, it must remain secret.
# We store it in the SSH_ID environment variable in Travis CI project settings.
# As environment variables can only contain text, our key files are transformed
# like this: tar, xz, base64. Then then can be decoded here. This is safe as
# Travis CI never shows the contents of secure variables.

# To generate the contents of the SSH_ID variable:
# Be sure to be in an empty, temporary directory.
#
# mkdir .ssh
# ssh-keygen -t rsa -b 4096 -C travis-ci.org/$USER/$PROJECT -N '' -f .ssh/id_rsa
# tar Jcvf id.tar.xz .ssh
# base64 -w 0 id.tar.xz
#
# Select the resulting encoded text (several lines) to copy it to the clipboard.
# Then go to the Travis CI project settings:
# https://travis-ci.org/$USER/$PROJECT/settings
# Create a new environment variable named SSH_ID, and paste the value.
# The script below will recreate the key files from that variable contents.

if [ -z ${SSH_ID+x} ]
then
echo "error: SSH_ID is undefined" >&2
exit 1
fi

echo $SSH_ID | base64 -d | tar -C ~ -Jx

ls -l ~/.ssh
40 changes: 40 additions & 0 deletions .scripts/setup_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh
# Use as: ". setup_env.sh"

PROJECT_REPO=$(echo "${GITHUB_REPOSITORY}" | cut -d '/' -f 1)
echo "PROJECT_REPO=${PROJECT_REPO}" >> $GITHUB_ENV
# PROJECT_NAME=$(echo "${GITHUB_REPOSITORY}" | cut -d '/' -f 2)
PROJECT_NAME=binutils
echo "PROJECT_NAME=${PROJECT_NAME}" >> $GITHUB_ENV
# PROJECT_VERSION is defined in the action script
echo "PROJECT_VERSION=${PROJECT_VERSION}" >> $GITHUB_ENV
INSTALL_DIR="/tmp/${PROJECT_NAME}"
echo "INSTALL_DIR=${INSTALL_DIR}" >> $GITHUB_ENV
DEPLOY_DIR="/tmp/${PROJECT_NAME}-deploy"
echo "DEPLOY_DIR=${DEPLOY_DIR}" >> $GITHUB_ENV
DEPLOY_ARCHIVE="tar.bz2"
echo "DEPLOY_ARCHIVE=${DEPLOY_ARCHIVE}" >> $GITHUB_ENV

SHORT_ID=$(echo ${GITHUB_SHA} | cut -c 1-3)
echo "SHORT_ID=$SHORT_ID" >> $GITHUB_ENV
LONG_ID=$(echo ${GITHUB_SHA} | cut -c 1-8)
echo "LONG_ID=$LONG_ID" >> $GITHUB_ENV
BRANCH=$(echo "${GITHUB_REF}" | cut -d '/' -f 3)

PROJECT_VERSION=`cat bfd/version.m4 | sed -n 's/.*\([0-9]\.[0-9][0-9]*\).*/\1/p'`
echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_ENV

if test "$CPU_TARGET" != ""; then
echo "CPU_TARGET=$CPU_TARGET" >> $GITHUB_ENV
fi
if test "$CROSS_TOOL" != ""; then
echo "CROSS_TOOL=$CROSS_TOOL" >> $GITHUB_ENV
fi

# GITHUB_HEAD_REF is only set for pull requests
if [ "${GITHUB_HEAD_REF}" = "" ]
then
COMMIT_MESSAGE="[${PROJECT_NAME}] [${BRANCH}] Commit: https://github.com/${PROJECT_REPO}/${PROJECT_NAME}/commit/${GITHUB_SHA}"
fi

echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> $GITHUB_ENV

0 comments on commit 410fb74

Please sign in to comment.