build #397
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build | |
on: | |
workflow_dispatch: | |
inputs: | |
build_image: | |
description: Build Docker images | |
required: false | |
type: boolean | |
default: false | |
push: | |
branches: | |
- main | |
schedule: | |
- cron: "0 0 * * *" | |
concurrency: | |
group: build | |
cancel-in-progress: true | |
jobs: | |
prepare: | |
name: Prepare build | |
runs-on: ubuntu-latest | |
outputs: | |
mold_stable_commit_sha: ${{ steps.determine_versions.outputs.mold_stable_commit_sha }} | |
mold_stable_commit_date: ${{ steps.determine_versions.outputs.mold_stable_commit_date }} | |
mold_stable_version: ${{ steps.determine_versions.outputs.mold_stable_version }} | |
mold_nightly_commit_sha: ${{ steps.determine_versions.outputs.mold_nightly_commit_sha }} | |
mold_nightly_commit_date: ${{ steps.determine_versions.outputs.mold_nightly_commit_date }} | |
mold_nightly_version: ${{ steps.determine_versions.outputs.mold_nightly_version }} | |
steps: | |
- name: Determine versions | |
id: determine_versions | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
mold_stable_tag="$(gh api /repos/rui314/mold/releases/latest -q .tag_name)" | |
mold_stable_commit_info="$(gh api "/repos/rui314/mold/commits/tags/$mold_stable_tag")" | |
mold_stable_commit_sha="$(jq --raw-output .sha <<<"$mold_stable_commit_info")" | |
mold_stable_commit_date="$(jq --raw-output .commit.committer.date <<<"$mold_stable_commit_info")" | |
mold_stable_version="${mold_stable_tag#v}" | |
mold_nightly_commit_info="$(gh api /repos/rui314/mold/commits/heads/main)" | |
mold_nightly_commit_sha="$(jq --raw-output .sha <<<"$mold_nightly_commit_info")" | |
mold_nightly_commit_date="$(jq --raw-output .commit.committer.date <<<"$mold_nightly_commit_info")" | |
mold_nightly_version="nightly" | |
{ | |
echo "mold_stable_commit_sha=$mold_stable_commit_sha" | |
echo "mold_stable_commit_date=$mold_stable_commit_date" | |
echo "mold_stable_version=$mold_stable_version" | |
echo "mold_nightly_commit_sha=$mold_nightly_commit_sha" | |
echo "mold_nightly_commit_date=$mold_nightly_commit_date" | |
echo "mold_nightly_version=$mold_nightly_version" | |
} | tee -a "$GITHUB_OUTPUT" | |
build: | |
needs: prepare | |
strategy: | |
matrix: | |
arch: | |
- x86_64 | |
- aarch64 | |
- arm | |
- riscv64 | |
- ppc64le | |
- s390x | |
variant: | |
- stable | |
- nightly | |
fail-fast: false | |
name: Build (${{ matrix.arch }} ${{ matrix.variant }}) | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Set up build | |
id: setup_build | |
run: | | |
case '${{ matrix.variant }}' in | |
stable) | |
mold_commit_sha='${{ needs.prepare.outputs.mold_stable_commit_sha }}' | |
mold_commit_date='${{ needs.prepare.outputs.mold_stable_commit_date }}' | |
build_prefix='mold-${{ needs.prepare.outputs.mold_stable_version }}-${{ matrix.arch }}-linux' | |
;; | |
nightly) | |
mold_commit_sha='${{ needs.prepare.outputs.mold_nightly_commit_sha }}' | |
mold_commit_date='${{ needs.prepare.outputs.mold_nightly_commit_date }}' | |
build_prefix='mold-${{ needs.prepare.outputs.mold_nightly_version }}-${{ matrix.arch }}-linux' | |
;; | |
esac | |
docker_platform='linux/${{ matrix.arch }}' | |
docker_image='mold-builder-${{ matrix.arch }}' | |
docker_file='${{ matrix.arch }}.Dockerfile' | |
{ | |
echo "mold_commit_sha=$mold_commit_sha" | |
echo "mold_commit_date=$mold_commit_date" | |
echo "build_prefix=$build_prefix" | |
echo "docker_platform=$docker_platform" | |
echo "docker_image=$docker_image" | |
echo "docker_file=$docker_file" | |
} | tee -a "$GITHUB_OUTPUT" | |
- name: Build Docker image | |
uses: docker/build-push-action@v3 | |
with: | |
platforms: ${{ steps.setup_build.outputs.docker_platform }} | |
tags: ${{ steps.setup_build.outputs.docker_image }} | |
file: ${{ steps.setup_build.outputs.docker_file }} | |
cache-from: type=gha | |
cache-to: type=gha | |
outputs: type=docker | |
- name: Build mold | |
id: build_mold | |
run: | | |
git clone https://github.com/rui314/mold.git mold | |
git -C mold checkout '${{ steps.setup_build.outputs.mold_commit_sha }}' | |
cp build-mold.sh mold/ | |
docker run \ | |
--rm \ | |
--interactive \ | |
--platform='${{ steps.setup_build.outputs.docker_platform }}' \ | |
--mount="type=bind,src=$PWD/mold,dst=/usr/local/src/mold" \ | |
--workdir="/usr/local/src/mold" \ | |
--env='BUILD_PREFIX=${{ steps.setup_build.outputs.build_prefix }}' \ | |
--env='TIMESTAMP=${{ steps.setup_build.outputs.mold_commit_date }}' \ | |
'${{ steps.setup_build.outputs.docker_image }}' \ | |
./build-mold.sh | |
build_output='${{ steps.setup_build.outputs.build_prefix }}.tar.gz' | |
echo "build_output=$build_output" | tee -a "$GITHUB_OUTPUT" | |
- name: Upload build output | |
uses: actions/upload-artifact@v3 | |
if: always() | |
with: | |
name: mold | |
path: 'mold/${{ steps.build_mold.outputs.build_output }}' | |
publish: | |
needs: [prepare, build] | |
name: Publish build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download build outputs | |
uses: actions/download-artifact@v3 | |
with: | |
name: mold | |
path: mold/ | |
- name: Get versions | |
id: get_versions | |
run: | | |
stable_build='mold-${{ needs.prepare.outputs.mold_stable_version }}-x86_64-linux' | |
tar -xzf "mold/$stable_build.tar.gz" | |
mold_stable_version_string="$("$stable_build/bin/mold" -v)" | |
nightly_build='mold-${{ needs.prepare.outputs.mold_nightly_version }}-x86_64-linux' | |
tar -xzf "mold/$nightly_build.tar.gz" | |
mold_nightly_version_string="$("$nightly_build/bin/mold" -v)" | |
{ | |
echo "mold_stable_version_string=$mold_stable_version_string" | |
echo "mold_nightly_version_string=$mold_nightly_version_string" | |
} | tee -a "$GITHUB_OUTPUT" | |
- name: Compute checksums | |
id: compute_checksums | |
run: | | |
cd mold | |
sha256sum mold*.tar.gz | tee SHA256SUMS | |
{ | |
echo "sha256sums<<EOF" | |
cat SHA256SUMS | |
echo "EOF" | |
} | tee -a "$GITHUB_OUTPUT" | |
- name: Determine release tag name | |
id: determine_tag_name | |
run: | | |
date="$(date +%Y%m%d)" | |
tag_name="" | |
for revision in {0..15}; do | |
if [[ -z "$(git ls-remote --tags origin "refs/tags/$date.$revision")" ]]; then | |
tag_name="$date.$revision" | |
break | |
fi | |
done | |
if [[ -z "$tag_name" ]]; then | |
echo "Error: too many revisions on $date. Aborting." >&2 | |
exit 1 | |
fi | |
echo "tag_name=$tag_name" | tee -a "$GITHUB_OUTPUT" | |
- name: Generate release notes | |
id: release_notes | |
run: | | |
release_title='mold nightly builds ${{ steps.determine_tag_name.outputs.tag_name }}' | |
notes_file="release-notes.md" | |
cat <<'EOF' | tee -a "$notes_file" | |
Stable: `${{ steps.get_versions.outputs.mold_stable_version_string }}` | |
Nightly: `${{ steps.get_versions.outputs.mold_nightly_version_string }}` | |
SHA-256 checksums: | |
``` | |
${{ steps.compute_checksums.outputs.sha256sums }} | |
``` | |
EOF | |
{ | |
echo "release_title=$release_title" | |
echo "notes_file=$notes_file" | |
} | tee -a "$GITHUB_OUTPUT" | |
- name: Publish release | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
gh release create \ | |
--latest \ | |
--title='${{ steps.release_notes.outputs.release_title }}' \ | |
--notes-file='${{ steps.release_notes.outputs.notes_file }}' \ | |
'${{ steps.determine_tag_name.outputs.tag_name }}' \ | |
mold/mold*.tar.gz \ | |
mold/SHA256SUMS |