diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f94737c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,113 @@ +# When a release is published, build the assets and upload them +name: Build release assets + +on: + release: + types: + - published + +jobs: + # First we define a job with a matrix that will build all relevant assets, + # and collect them in a temporary storage using `actions/upload-artifacts` + build: + name: 'Build artifacts for ${{ github.event.release.tag_name }}' + strategy: + fail-fast: false + matrix: + os: [ macOS-11, ubuntu-20.04, windows-2019 ] + arch: [ x86_64 ] + include: + - { os: windows-2019, arch: i686 } + + runs-on: ${{ matrix.os }} + steps: + ## Dependencies + - name: '[OSX] Install dependencies' + if: runner.os == 'macOS' + run: | + brew install pkg-config coreutils + echo "PKG_CONFIG_PATH=/usr/local/opt/openssl@1.1/lib/pkgconfig/" >> $GITHUB_ENV + - name: '[Linux] Install dependencies' + if: runner.os == 'Linux' + run: | + sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev + + ## Boileterplate (compiler/repo) + - name: Install compiler + uses: dlang-community/setup-dlang@v1 + with: + compiler: ldc-latest + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.release.tag_name }} + + ## Actually build the releases + - name: '[POSIX] Build release' + if: runner.os == 'Linux' || runner.os == 'macOS' + env: + GITVER: ${{ github.event.release.tag_name }} + DMD: "ldmd2" + ARCH_TRIPLE: ${{ matrix.arch }}-${{ runner.os == 'linux' && 'pc-linux' || 'apple-darwin' }} + run: | + ldc2 -run ./build.d -release -mtriple=${ARCH_TRIPLE} + pushd bin + if [ ${{ runner.os }} == 'Linux' ]; then + tar -c -f 'dub-${{ github.event.release.tag_name }}-linux-${{ matrix.arch }}.tar.gz' -v -z --owner=0 --group=0 dub + else + gtar -c -f 'dub-${{ github.event.release.tag_name }}-osx-${{ matrix.arch }}.tar.gz' -v -z --owner=0 --group=0 dub + fi + popd + - name: '[Windows] Build release' + if: runner.os == 'Windows' + env: + GITVER: ${{ github.event.release.tag_name }} + DMD: "ldmd2" + run: | + ldc2 -run ./build.d -release -mtriple=${{ matrix.arch }}-pc-windows-msvc + pushd bin + 7z a dub-${{ github.event.release.tag_name }}-windows-${{ matrix.arch }}.zip dub.exe + popd + + - name: 'Upload temporary binaries' + uses: actions/upload-artifact@v4 + with: + name: dub-release-${{ matrix.os }}-${{ matrix.arch }} + path: | + bin/dub-${{ github.event.release.tag_name }}-* + if-no-files-found: error + retention-days: 1 + + # Uploads collected builds to the release + release: + name: "Update release artifacts" + runs-on: ubuntu-latest + needs: + - build + + steps: + - name: Download artifacts to release + uses: actions/download-artifact@v4 + with: + path: ~/artifacts/ + + - name: List all artifacts included in the release + id: list-artifacts + shell: bash + run: | + set -euox pipefail + ls -aulR ~/artifacts + echo "artifacts_directory=$HOME/artifacts" >> $GITHUB_OUTPUT + + - name: Update release artifacts + uses: ncipollo/release-action@v1 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + tag: ${{ github.event.release.tag_name }} + artifacts: ${{ steps.list-artifacts.outputs.artifacts_directory }}/*/* + # Keep the existing state of the release + allowUpdates: true + artifactErrorsFailBuild: true + omitNameDuringUpdate: true + omitBodyDuringUpdate: true + omitPrereleaseDuringUpdate: true diff --git a/scripts/ci/release-windows.sh b/scripts/ci/release-windows.sh deleted file mode 100755 index 5b87df2..0000000 --- a/scripts/ci/release-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# Build the Windows binaries under Linux -set -eux -o pipefail - -BIN_NAME=dub - -# Allow the script to be run from anywhere -DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")/../../" && pwd )" -cd $DIR - -# Setup cross compiler -source scripts/ci/setup-ldc-windows.sh - -# Run LDC with cross-compilation -archiveName="$BIN_NAME-$VERSION-$OS-$ARCH_SUFFIX.zip" -echo "Building $archiveName" -mkdir -p bin -DMD=ldmd2 ldc2 -run ./build.d -release ${LDC_XDFLAGS} - -cd bin -zip "$archiveName" "${BIN_NAME}.exe" diff --git a/scripts/ci/release.sh b/scripts/ci/release.sh deleted file mode 100755 index bdc45da..0000000 --- a/scripts/ci/release.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash - -set -eux -o pipefail - -# Get the directory root, which is two level ahead -ROOT_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")/../../" && pwd )" -cd ${ROOT_DIR} - -VERSION=$(git describe --abbrev=0 --tags) -ARCH="${ARCH:-64}" -CUSTOM_FLAGS=() -unameOut="$(uname -s)" -case "$unameOut" in - Linux*) - OS=linux - CUSTOM_FLAGS+=("-L--export-dynamic") - ;; - Darwin*) - OS=osx - CUSTOM_FLAGS+=("-L-dead_strip") - ;; - *) echo "Unknown OS: $unameOut"; exit 1 -esac - -if [[ $(basename "$DMD") =~ ldmd.* ]] ; then - CUSTOM_FLAGS+=("-flto=full") - # ld.gold is required on Linux - if [ ${OS:-} == "linux" ] ; then - CUSTOM_FLAGS+=("-linker=gold") - fi -fi - -case "$ARCH" in - 64) ARCH_SUFFIX="x86_64";; - 32) ARCH_SUFFIX="x86";; - *) echo "Unknown ARCH: $ARCH"; exit 1 -esac - -archiveName="dub-$VERSION-$OS-$ARCH_SUFFIX.tar.gz" - -echo "Building $archiveName" -DMD="$(command -v $DMD)" ./build.d -release -m$ARCH ${CUSTOM_FLAGS[@]} -if [[ "$OSTYPE" == darwin* ]]; then - TAR=gtar -else - TAR=tar -fi - -"$TAR" cvfz "bin/$archiveName" --owner=0 --group=0 -C bin dub diff --git a/scripts/ci/setup-ldc-windows.sh b/scripts/ci/setup-ldc-windows.sh deleted file mode 100644 index ec70e9c..0000000 --- a/scripts/ci/setup-ldc-windows.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash - -# sets up LDC for cross-compilation. Source this script, s.t. the new LDC is in PATH - -# Make sure this version matches the version of LDC2 used in the CI configuration -# otherwise the compiler and the lib used might mismatch. -LDC_VERSION="1.22.0" -ARCH=${ARCH:-32} -VERSION=$(git describe --abbrev=0 --tags) -OS=windows - -# LDC should already be installed (see .travis.yml) -# However, we need the libraries, so download them -# We can't use the downloaded ldc2 itself, because obviously it's for Windows - -if [ "${ARCH}" == 64 ]; then - ARCH_SUFFIX='x86_64' - ZIP_ARCH_SUFFIX='x64' -else - ARCH_SUFFIX='i686' - ZIP_ARCH_SUFFIX='x86' -fi - -LDC_DIR_PATH="$(pwd)/ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}" -LDC_XDFLAGS="-conf=${LDC_DIR_PATH}/etc/ldc2.conf -mtriple=${ARCH_SUFFIX}-pc-windows-msvc" - -# Step 1: download the LDC Windows release -# Check if the user already have it (e.g. building locally) -if [ ! -d ${LDC_DIR_PATH} ]; then - if [ ! -d "ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}.7z" ]; then - wget "https://github.com/ldc-developers/ldc/releases/download/v${LDC_VERSION}/ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}.7z" - fi - 7z x "ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}.7z" > /dev/null -fi - -# Step 2: Generate a config file with the proper path -cat > ${LDC_DIR_PATH}/etc/ldc2.conf <