Skip to content

Commit

Permalink
Add CI release pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-carlborg committed Mar 20, 2024
1 parent 2f72e6c commit b67682c
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 13 deletions.
109 changes: 106 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ on:
schedule:
- cron: 0 0 * * *

env:
MACOSX_DEPLOYMENT_TARGET: 10.9

defaults:
run:
shell: bash
Expand Down Expand Up @@ -89,6 +86,14 @@ jobs:
host: windows-latest
target_triple: x86_64-pc-windows-msvc

# - compiler: dmd-latest
# llvm: '15.0.7'
# arch: x86
# data:
# os:
# host: windows-latest
# target_triple: x86-pc-windows-msvc

steps:
- name: Clone Repository
uses: actions/checkout@v3
Expand All @@ -109,3 +114,101 @@ jobs:
cross_platform_actions: ${{ matrix.data.cross_platform_actions }}
docker: ${{ matrix.data.docker }}
compiler: ${{ matrix.compiler }}

create_release:
name: Create Release ${{ matrix.data.os.target_triple }}
needs: test
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ${{ matrix.data.os.host }}
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
arch: [x86_64]
data:
- os:
host: ubuntu-latest
target_triple: x86_64-alpine-linux-musl
docker: true
release_platform: linux-x86_64

- os:
host: macOS-latest
target_triple: x86_64-apple-macos10.9
release_platform: macos-x86_64

- os:
host: windows-latest
target_triple: x86_64-pc-windows-msvc
release_platform: windows-x64

- os:
target: freebsd
version: '13.1'
target_triple: x86_64-unknown-freebsd13.1
host: ubuntu-latest
cross_platform_actions: true
release_platform: freebsd13.1-x86_64

compiler:
- ldc-latest

llvm:
- '15.0.7'

# include:
# - compiler: ldc-latest
# llvm: '15.0.7'
# arch: x86
# data:
# os:
# host: windows-latest
# target_triple: x86-pc-windows-msvc
# release_platform: windows-x86

steps:
- name: Clone Repository
uses: actions/checkout@v3
with:
persist-credentials: false
fetch-depth: 0

- name: Build Release
uses: ./.github/workflows/support/build
with:
action: release
arch: ${{ matrix.arch }}
docker_arch: ${{ matrix.docker_arch }}
target_operating_system: ${{ matrix.data.os.target }}
target_version: ${{ matrix.data.os.version }}
llvm: ${{ matrix.llvm }}
target_triple: ${{ matrix.data.os.target_triple }}
cross_platform_actions: ${{ matrix.data.cross_platform_actions }}
docker: ${{ matrix.data.docker }}
compiler: ${{ matrix.compiler }}
release_platform: ${{ matrix.data.release_platform }}

- name: Extract Version
id: version
run: echo version="${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT"

- name: Extract changelog
if: runner.os == 'Linux'
uses: sean0x42/markdown-extract@v2
id: extract_changelog
with:
file: changelog.md
pattern: '\[${{ steps.version.outputs.version }}\].+'
no-print-matched-heading: true

- name: Create release
uses: softprops/action-gh-release@v1
with:
name: DStep ${{ steps.version.outputs.version }}
draft: true
body: ${{ steps.extract_changelog.outputs.markdown }}
files: |
dstep*.tar.xz
dstep*.7z
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38 changes: 32 additions & 6 deletions .github/workflows/support/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ inputs:
description: "The target operating system"
target_version:
description: "The target operating system version"
llvm:
description: "The version of LLVM"
target_triple:
description: "The target triple"
release_platform:
description: "The name of the platform used for releases"
llvm:
description: "The version of LLVM"
cross_platform_actions:
description: "Indicates if the Cross Platform Action should be used"
docker:
Expand All @@ -25,12 +27,14 @@ runs:
steps:
- name: Download LLVM
if: runner.os != 'Windows'
shell: bash
run: |
curl -f -L -o llvm.tar.xz --retry 3 'https://github.com/jacob-carlborg/clang-builder/releases/download/v${{ inputs.llvm }}%2B0.0.2-rc2/llvm-${{ inputs.llvm }}-${{ inputs.target_triple }}.tar.xz'
tar xf llvm.tar.xz
- name: Download LLVM
if: runner.os == 'Windows'
shell: bash
run: |
curl -f -L -o llvm.7z --retry 3 'https://github.com/jacob-carlborg/clang-builder/releases/download/v${{ inputs.llvm }}%2B0.0.2-rc2/llvm-${{ inputs.llvm }}-${{ inputs.target_triple }}.7z'
7z x llvm.7z
Expand All @@ -42,18 +46,32 @@ runs:

- name: Test
if: ${{ !inputs.cross_platform_actions && !inputs.docker }}
shell: bash
env:
DSTEP_LLVM_VERSION: ${{ inputs.llvm }}
DSTEP_COMPILER: ${{ inputs.compiler }}
DSTEP_RELEASE_PLATFORM: ${{ inputs.release_platform }}
DSTEP_TARGET_TRIPLE: ${{ inputs.target_triple }}
run: ./ci.sh ${{ inputs.action }}

- name: Test
if: inputs.cross_platform_actions
env:
DSTEP_LLVM_VERSION: ${{ inputs.llvm }}
DSTEP_COMPILER: ${{ inputs.compiler }}
DSTEP_RELEASE_PLATFORM: ${{ inputs.release_platform }}
DSTEP_TARGET_TRIPLE: ${{ inputs.target_triple }}
uses: cross-platform-actions/action@v0.23.0
with:
shell: bash
operating_system: ${{ inputs.target_operating_system }}
version: ${{ inputs.target_version }}
environment_variables: >-
DSTEP_LLVM_VERSION
DSTEP_COMPILER
DSTEP_RELEASE_PLATFORM
DSTEP_TARGET_TRIPLE
run: |
export DSTEP_LLVM_VERSION="${{ inputs.llvm }}"
export DSTEP_COMPILER="${{ inputs.compiler }}"
sudo pkg install -y llvm git gnupg
./ci.sh ${{ inputs.action }}
Expand All @@ -65,13 +83,21 @@ runs:

- name: Run Tests in Docker
if: inputs.docker
shell: bash
env:
DSTEP_LLVM_VERSION: ${{ inputs.llvm }}
DSTEP_COMPILER: ${{ inputs.compiler }}
DSTEP_RELEASE_PLATFORM: ${{ inputs.release_platform }}
DSTEP_TARGET_TRIPLE: ${{ inputs.target_triple }}
run: |
docker run \
--rm \
-v $(pwd):/${{ github.workspace }} \
-w ${{ github.workspace }} \
-e DSTEP_LLVM_VERSION=${{ inputs.llvm }} \
-e DSTEP_COMPILER=${{ inputs.compiler }} \
-e DSTEP_LLVM_VERSION=${{ env.DSTEP_LLVM_VERSION }} \
-e DSTEP_COMPILER=${{ env.DSTEP_COMPILER }} \
-e DSTEP_RELEASE_PLATFORM=${{ env.DSTEP_RELEASE_PLATFORM }} \
-e DSTEP_TARGET_TRIPLE=${{ env.DSTEP_TARGET_TRIPLE }} \
--platform linux/${{ inputs.docker_arch || inputs.arch }} \
alpine:edge \
apk add --no-cache git curl bash && \
Expand Down
1 change: 0 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* Building DStep now requires libclang 15.0.7
* Automatically detect macOS SDK path ([Issue 227](https://github.com/jacob-carlborg/dstep/issues/227))
* Add support for FreeBSD
* Drop support for Windows 32 bit
* [Issue 287](https://github.com/jacob-carlborg/dstep/issues/287): Add support for adding public imports
* [Issue 288](https://github.com/jacob-carlborg/dstep/issues/288): Missing `__u/int128` support

Expand Down
56 changes: 53 additions & 3 deletions ci.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#!/usr/bin/env bash

# Environment variables:
# DSTEP_COMPILER: the compiler to build with
# DSTEP_LLVM_VERSION: the version of LLVM to link with
# DSTEP_TARGET_TRIPLE: the target triple to build for
# DSTEP_RELEASE_PLATFORM: the name of the platform

set -exo pipefail

export MACOSX_DEPLOYMENT_TARGET=10.9

download() {
curl --retry 3 -fsS "$1"
}
Expand All @@ -17,10 +25,52 @@ install_d_compiler() {
source $(download https://dlang.org/install.sh | bash -s "$(d_compiler)" -a)
}

run() {
configure() {
./configure --llvm-path "llvm-$DSTEP_LLVM_VERSION" --statically-link-clang
dub test --verror
}

target_triple_arg() {
if echo "$(d_compiler)" | grep -i -q ldc; then
echo "--mtriple=$DSTEP_TARGET_TRIPLE"
else
echo "-target=$DSTEP_TARGET_TRIPLE"
fi
}

run_tests() {
DFLAGS="$(target_triple_arg)" dub test --verror
}

release() {
DFLAGS="$(target_triple_arg)" dub build -b release --verror
strip "$target_path"*
archive
}

version() {
"$target_path"* --version
}

release_name() {
echo "$app_name-$(version)-$DSTEP_RELEASE_PLATFORM"
}

archive() {
if uname | grep -i -q mingw; then
7z a "$(release_name).7z" "$target_path"*
else
tar Jcf "$(release_name).tar.xz" -C "$target_dir" "$app_name"
fi
}

app_name="dstep"
target_dir="bin"
target_path="$target_dir/$app_name"

install_d_compiler
run
configure

case "$1" in
'test') run_tests ;;
'release') release ;;
esac

0 comments on commit b67682c

Please sign in to comment.