Skip to content

Commit

Permalink
CI: build tmbasic
Browse files Browse the repository at this point in the history
  • Loading branch information
electroly committed Nov 11, 2023
1 parent b4f6471 commit fda532e
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 58 deletions.
278 changes: 278 additions & 0 deletions .github/workflows/tmbasic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
name: TMBASIC
on: workflow_dispatch

jobs:
build-runner-docker:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- platform: linux-arm64
- platform: linux-arm32
- platform: linux-x64
- platform: linux-x86
- platform: win-x64
- platform: win-x86
name: runner-${{ matrix.platform }}
- name: Checkout
uses: actions/checkout@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build
env:
NO_BUILD: 1
run: |
set -euxo pipefail
cd build
export IMAGE_TAG=$(awk -F= '{ if ($1 == "build-environment-${{ matrix.platform }}") print $2 }' tags.ini)
export IMAGE_NAME="ghcr.io/electroly/tmbasic-build-env:$IMAGE_TAG"
docker pull "$IMAGE_NAME"
./${{ matrix.platform }}.sh -c "make runner"
- name: Upload runner.gz
uses: actions/upload-artifact@v2
with:
name: runner-${{ matrix.platform }}.gz
path: bin/runner.gz

build-runner-mac:
# Our build process requires an M1 Mac; it won't work on an Intel Mac.
runs-on: macos-latest-xlarge
strategy:
matrix:
include:
- platform: mac-arm64
- platform: mac-x64
name: runner-${{ matrix.platform }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
AWS_DEFAULT_OUTPUT: json
run: |
set -euxo pipefail
# https://github.com/actions/runner-images/issues/8613
brew install awscli
export FILENAME=$(awk -F= '{ if ($1 == "build-environment-${{ matrix.platform }}") print $2 }' tags.ini)
export S3_URL="s3://tmbasic/mac-build-envs/$FILENAME"
aws s3 cp "$S3_URL" build-environment.tar.gz
tar zxvf build-environment.tar.gz
cd build
./${{ matrix.platform }}.sh -c "make runner"
- name: Upload runner.gz
uses: actions/upload-artifact@v2
with:
name: runner-${{ matrix.platform }}.gz
path: bin/runner.gz

gather-runners:
runs-on: ubuntu-latest
name: Gather Runners
needs: [build-runner-docker, build-runner-mac]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download runner-linux-arm64.gz
uses: actions/download-artifact@v3
with:
name: runner-linux-arm64.gz

- name: Download runner-linux-arm32.gz
uses: actions/download-artifact@v3
with:
name: runner-linux-arm32.gz

- name: Download runner-linux-x64.gz
uses: actions/download-artifact@v3
with:
name: runner-linux-x64.gz

- name: Download runner-linux-x86.gz
uses: actions/download-artifact@v3
with:
name: runner-linux-x86.gz

- name: Download runner-win-x64.gz
uses: actions/download-artifact@v3
with:
name: runner-win-x64.gz

- name: Download runner-win-x86.gz
uses: actions/download-artifact@v3
with:
name: runner-win-x86.gz

- name: Download runner-mac-arm64.gz
uses: actions/download-artifact@v3
with:
name: runner-mac-arm64.gz

- name: Download runner-mac-x64.gz
uses: actions/download-artifact@v3
with:
name: runner-mac-x64.gz

- name: Combine
run: |
set -euxo pipefail
tar cvf runners.tar runner-*.gz
- name: Upload runners.tar
uses: actions/upload-artifact@v2
with:
name: runners.tar
path: runners.tar

- name: Delete runner-*.gz
uses: geekyeggo/delete-artifact@v2
with:
useGlob: false
name: |
runner-linux-arm64.gz
runner-linux-arm32.gz
runner-linux-x64.gz
runner-linux-x86.gz
runner-win-x64.gz
runner-win-x86.gz
runner-mac-arm64.gz
runner-mac-x64.gz
build-tmbasic-docker:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- platform: linux-arm64
format: tar.gz
- platform: linux-arm32
format: tar.gz
- platform: linux-x64
format: tar.gz
- platform: linux-x86
format: tar.gz
- platform: win-x64
format: zip
- platform: win-x86
format: zip
name: tmbasic-${{ matrix.platform }}
needs: gather-runners
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download runners.tar
uses: actions/download-artifact@v2
with:
name: runners.tar

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build
env:
NO_BUILD: 1
run: |
set -euxo pipefail
cd build
export IMAGE_TAG=$(awk -F= '{ if ($1 == "build-environment-${{ matrix.platform }}") print $2 }' tags.ini)
export IMAGE_NAME="ghcr.io/electroly/tmbasic-build-env:$IMAGE_TAG"
docker pull "$IMAGE_NAME"
./${{ matrix.platform }}.sh -c "make release"
pushd bin
if [ "${{ matrix.format }}" = "zip" ]; then
zip -9 tmbasic.zip tmbasic
else
tar cvf tmbasic.tar.gz tmbasic
fi
popd
- name: Upload tmbasic.zip
if: matrix.format == 'zip'
uses: actions/upload-artifact@v2
with:
name: tmbasic-${{ matrix.platform }}.zip
path: bin/tmbasic.zip

- name: Upload tmbasic.tar.gz
if: matrix.format == 'tar.gz'
uses: actions/upload-artifact@v2
with:
name: tmbasic-${{ matrix.platform }}.tar.gz
path: bin/tmbasic.tar.gz

build-tmbasic-mac:
# Our build process requires an M1 Mac; it won't work on an Intel Mac.
runs-on: macos-latest-xlarge
strategy:
matrix:
include:
- platform: mac-arm64
- platform: mac-x64
name: tmbasic-${{ matrix.platform }}
needs: gather-runners
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download runners.tar
uses: actions/download-artifact@v2
with:
name: runners.tar

- name: Build
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
AWS_DEFAULT_OUTPUT: json
run: |
set -euxo pipefail
# https://github.com/actions/runner-images/issues/8613
brew install awscli
export FILENAME=$(awk -F= '{ if ($1 == "build-environment-${{ matrix.platform }}") print $2 }' tags.ini)
export S3_URL="s3://tmbasic/mac-build-envs/$FILENAME"
aws s3 cp "$S3_URL" build-environment.tar.gz
tar zxvf build-environment.tar.gz
mkdir -p obj/resources/runners/
tar zxvf runners.tar -C obj/resources/runners/
cd build
./${{ matrix.platform }}.sh -c "make release"
pushd bin
zip -9 tmbasic.zip tmbasic
popd
- name: Upload tmbasic.zip
uses: actions/upload-artifact@v2
with:
name: tmbasic-${{ matrix.platform }}.zip
path: bin/tmbasic.zip
23 changes: 13 additions & 10 deletions build/linux-arm32.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Optional parameters: $IMAGE_NAME, $PUSH_ONLY, $HOST_UID, $HOST_GID
# Optional parameters: $IMAGE_NAME, $NO_BUILD, $PUSH_ONLY, $HOST_UID, $HOST_GID
set -euxo pipefail

export IMAGE_NAME=${IMAGE_NAME:="tmbasic-linux-arm32"}
Expand All @@ -9,17 +9,20 @@ export DOCKER_ARCH="arm32v7"
export ARCH="arm32v7"
export TRIPLE="armv7-alpine-linux-musleabihf"

scripts/sysrootDownload.sh
scripts/depsDownload.sh
# Build unless $NO_BUILD is non-empty.
if [ -z "${NO_BUILD+x}" ]; then
scripts/sysrootDownload.sh
scripts/depsDownload.sh

# If $PUSH_ONLY is non-empty, then set the --push argument.
export BUILDX_FLAGS=""
if [ -n "${PUSH_ONLY+x}" ]; then
export BUILDX_FLAGS="--push"
fi
# If $PUSH_ONLY is non-empty, then set the --push argument.
export BUILDX_FLAGS=""
if [ -n "${PUSH_ONLY+x}" ]; then
export BUILDX_FLAGS="--push"
fi

if [ "$(docker image ls $IMAGE_NAME | wc -l)" == "1" ]; then
cat files/Dockerfile.build-linux | sed "s=\$IMAGE_NAME=$IMAGE_NAME=g; s/\$HOST_UID/$HOST_UID/g; s/\$HOST_GID/$HOST_GID/g; s/\$DOCKER_ARCH/$DOCKER_ARCH/g; s/\$ARCH/$ARCH/g; s/\$USER/$USER/g; s/\$TRIPLE/$TRIPLE/g" | docker buildx build $BUILDX_FLAGS -t $IMAGE_NAME files -f-
if [ "$(docker image ls $IMAGE_NAME | wc -l)" == "1" ]; then
cat files/Dockerfile.build-linux | sed "s=\$IMAGE_NAME=$IMAGE_NAME=g; s/\$HOST_UID/$HOST_UID/g; s/\$HOST_GID/$HOST_GID/g; s/\$DOCKER_ARCH/$DOCKER_ARCH/g; s/\$ARCH/$ARCH/g; s/\$USER/$USER/g; s/\$TRIPLE/$TRIPLE/g" | docker buildx build $BUILDX_FLAGS -t $IMAGE_NAME files -f-
fi
fi

# If $PUSH_ONLY is empty or unset, then run.
Expand Down
23 changes: 13 additions & 10 deletions build/linux-arm64.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Optional parameters: $IMAGE_NAME, $PUSH_ONLY, $HOST_UID, $HOST_GID
# Optional parameters: $IMAGE_NAME, $NO_BUILD, $PUSH_ONLY, $HOST_UID, $HOST_GID
set -euxo pipefail

export IMAGE_NAME=${IMAGE_NAME:="tmbasic-linux-arm64"}
Expand All @@ -9,17 +9,20 @@ export DOCKER_ARCH="arm64v8"
export ARCH="arm64v8"
export TRIPLE="aarch64-alpine-linux-musl"

scripts/sysrootDownload.sh
scripts/depsDownload.sh
# Build unless $NO_BUILD is non-empty.
if [ -z "${NO_BUILD+x}" ]; then
scripts/sysrootDownload.sh
scripts/depsDownload.sh

# If $PUSH_ONLY is non-empty, then set the --push argument.
export BUILDX_FLAGS=""
if [ -n "${PUSH_ONLY+x}" ]; then
export BUILDX_FLAGS="--push"
fi
# If $PUSH_ONLY is non-empty, then set the --push argument.
export BUILDX_FLAGS=""
if [ -n "${PUSH_ONLY+x}" ]; then
export BUILDX_FLAGS="--push"
fi

if [ "$(docker image ls $IMAGE_NAME | wc -l)" == "1" ]; then
cat files/Dockerfile.build-linux | sed "s=\$IMAGE_NAME=$IMAGE_NAME=g; s/\$HOST_UID/$HOST_UID/g; s/\$HOST_GID/$HOST_GID/g; s/\$DOCKER_ARCH/$DOCKER_ARCH/g; s/\$ARCH/$ARCH/g; s/\$USER/$USER/g; s/\$TRIPLE/$TRIPLE/g" | docker buildx build $BUILDX_FLAGS -t $IMAGE_NAME files -f-
if [ "$(docker image ls $IMAGE_NAME | wc -l)" == "1" ]; then
cat files/Dockerfile.build-linux | sed "s=\$IMAGE_NAME=$IMAGE_NAME=g; s/\$HOST_UID/$HOST_UID/g; s/\$HOST_GID/$HOST_GID/g; s/\$DOCKER_ARCH/$DOCKER_ARCH/g; s/\$ARCH/$ARCH/g; s/\$USER/$USER/g; s/\$TRIPLE/$TRIPLE/g" | docker buildx build $BUILDX_FLAGS -t $IMAGE_NAME files -f-
fi
fi

# If $PUSH_ONLY is empty or unset, then run.
Expand Down
23 changes: 13 additions & 10 deletions build/linux-x64.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Optional parameters: $IMAGE_NAME, $PUSH_ONLY, $HOST_UID, $HOST_GID
# Optional parameters: $IMAGE_NAME, $NO_BUILD, $PUSH_ONLY, $HOST_UID, $HOST_GID
set -euxo pipefail

export IMAGE_NAME=${IMAGE_NAME:="tmbasic-linux-x64"}
Expand All @@ -9,17 +9,20 @@ export DOCKER_ARCH="amd64"
export ARCH="x86_64"
export TRIPLE="x86_64-alpine-linux-musl"

scripts/sysrootDownload.sh
scripts/depsDownload.sh
# Build unless $NO_BUILD is non-empty.
if [ -z "${NO_BUILD+x}" ]; then
scripts/sysrootDownload.sh
scripts/depsDownload.sh

# If $PUSH_ONLY is non-empty, then set the --push argument.
export BUILDX_FLAGS=""
if [ -n "${PUSH_ONLY+x}" ]; then
export BUILDX_FLAGS="--push"
fi
# If $PUSH_ONLY is non-empty, then set the --push argument.
export BUILDX_FLAGS=""
if [ -n "${PUSH_ONLY+x}" ]; then
export BUILDX_FLAGS="--push"
fi

if [ "$(docker image ls $IMAGE_NAME | wc -l)" == "1" ]; then
cat files/Dockerfile.build-linux | sed "s=\$IMAGE_NAME=$IMAGE_NAME=g; s/\$HOST_UID/$HOST_UID/g; s/\$HOST_GID/$HOST_GID/g; s/\$DOCKER_ARCH/$DOCKER_ARCH/g; s/\$ARCH/$ARCH/g; s/\$USER/$USER/g; s/\$TRIPLE/$TRIPLE/g" | docker buildx build $BUILDX_FLAGS -t $IMAGE_NAME files -f-
if [ "$(docker image ls $IMAGE_NAME | wc -l)" == "1" ]; then
cat files/Dockerfile.build-linux | sed "s=\$IMAGE_NAME=$IMAGE_NAME=g; s/\$HOST_UID/$HOST_UID/g; s/\$HOST_GID/$HOST_GID/g; s/\$DOCKER_ARCH/$DOCKER_ARCH/g; s/\$ARCH/$ARCH/g; s/\$USER/$USER/g; s/\$TRIPLE/$TRIPLE/g" | docker buildx build $BUILDX_FLAGS -t $IMAGE_NAME files -f-
fi
fi

# If $PUSH_ONLY is empty or unset, then run.
Expand Down
Loading

0 comments on commit fda532e

Please sign in to comment.