Skip to content

Commit

Permalink
Introduce Github Action to build Darwin packages.
Browse files Browse the repository at this point in the history
Allow to run build scripts for darwin to test changes in PR.
  • Loading branch information
miry committed Jan 10, 2024
1 parent 9d6e645 commit c43b020
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
92 changes: 92 additions & 0 deletions .github/workflows/darwin_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Darwin Package Build

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
LOG_LEVEL: debug

jobs:
dist_darwin:
runs-on: macos-11

steps:
-
name: Select Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '13.2.1'

- # Reference: https://github.com/actions/checkout#Checkout-multiple-repos-side-by-side
name: Download distribution-scripts sources
uses: actions/checkout@v4
with:
path: distribution-scripts

-
name: Download crystal sources
uses: actions/checkout@v4
with:
repository: crystal-lang/crystal
path: crystal
fetch-tags: true
fetch-depth: 0

-
name: Cache Omnibus Depenedcies
uses: actions/cache@v3
with:
path: distribution-scripts/omnibus/vendor/bundler
key: ${{ runner.os }}-omnibus-bundler-${{ hashFiles('distribution-scripts/omnibus/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-omnibus-bundler-
${{ runner.os }}-
-
name: Install Omnibus Depenedcies
run: |
make -C distribution-scripts omnibus_setup
-
name: Create build folders
run: |
sudo mkdir -p /opt/crystal
sudo chown $(whoami) /opt/crystal/
sudo mkdir -p /var/cache
sudo chown $(whoami) /var/cache
-
name: Build Dawin package
run: |
make -C distribution-scripts/darwin \
OMNIBUS_OPTS="--log-level ${{ env.LOG_LEVEL }} --override use_git_caching:false" \
CRYSTAL_REPO=$GITHUB_WORKSPACE/crystal \
CRYSTAL_SRC=$GITHUB_WORKSPACE/crystal \
CRYSTAL_SHA1=master \
CRYSTAL_VERSION=1.11.0 \
PACKAGE_ITERATION=1 \
LLVM_VERSION=15.0.7 \
PREVIOUS_CRYSTAL_RELEASE_DARWIN_TARGZ=https://github.com/crystal-lang/crystal/releases/download/1.10.1/crystal-1.10.1-1-darwin-universal.tar.gz
- # Reference: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files
name: Extract the package name to be used for the artifact name
run: |
cd distribution-scripts/darwin/build
ls -la
filename=$(ls -1 crystal-*.tar.gz)
echo "ARTIFACT_NAME=${filename%.tar.gz}" >> "$GITHUB_ENV"
- # When an Artifact is uploaded, all the files are assembled into an immutable Zip archive.
# https://github.com/actions/upload-artifact#zip-archives
name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: distribution-scripts/darwin/build/*
retention-days: 1
if-no-files-found: error
compression-level: 0 # package is already compressed
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.PHONY: darwin
darwin: omnibus_setup
FORCE_GIT_TAGGED=0 \
CRYSTAL_REPO=https://github.com/crystal-lang/crystal \
CRYSTAL_SHA1=master \
CRYSTAL_VERSION=1.10.1 \
PREVIOUS_CRYSTAL_RELEASE_DARWIN_TARGZ=https://github.com/crystal-lang/crystal/releases/download/1.10.1/crystal-1.10.1-1-darwin-universal.tar.gz \
make -C darwin

# https://github.com/chef/omnibus
.PHONY: omnibus_setup
omnibus_setup:
cd omnibus && bundle install --path vendor/bundler

.PHONY: clean
clean:
make -C darwin clean
3 changes: 2 additions & 1 deletion darwin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ FORCE_GIT_TAGGED ?= 1 ## Require build to be based on git tag/branc

PREVIOUS_CRYSTAL_RELEASE_DARWIN_TARGZ ?= ## url to crystal-{version}-{package}-darwin-x86_64.tar.gz

OMNIBUS_OPTS ?= ## Build arguments for omnibus command line
OUTPUT_DIR = build

# mimics the tgz_package.rb version mangling
Expand Down Expand Up @@ -65,7 +66,7 @@ endif
&& export MACOSX_DEPLOYMENT_TARGET=11.0 \
&& export SDKROOT=$(shell xcrun --sdk macosx --show-sdk-path) \
&& bundle exec omnibus clean crystal shards \
&& bundle exec omnibus build crystal \
&& bundle exec omnibus build crystal $(OMNIBUS_OPTS) \
&& cp ./pkg/$(DARWIN_NAME) $(CURDIR)/$(OUTPUT_DIR)/$(subst x86_64,universal,$(DARWIN_NAME)) \
&& cp ./pkg/$(DARWIN_PKG_NAME) $(CURDIR)/$(OUTPUT_DIR)/$(subst x86_64,universal,$(DARWIN_PKG_NAME))

Expand Down

0 comments on commit c43b020

Please sign in to comment.