Skip to content

Prefetch MoonBit

Prefetch MoonBit #551

Workflow file for this run

name: Prefetch MoonBit
on:
schedule:
- cron: '0 2 * * *' # *-*-* 02:00:00 UTC
workflow_dispatch:
push:
branches:
- master
paths:
- .github/workflows/sync.yaml
- scripts/fetch_toolchains.sh
- lib/moon-patched/update.sh
permissions:
contents: write
jobs:
prefetch-moonbit:
name: Prefetch MoonBit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Nix
uses: nixbuild/nix-quick-install-action@v30
- uses: nix-community/cache-nix-action@v6
with:
# restore and save a cache using this key
primary-key: build-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
# if there's no cache hit, restore a cache by this prefix
restore-prefixes-first-match: build-${{ runner.os }}-
# collect garbage until Nix store size (in bytes) is at most this number
# before trying to save a new cache
# 1G = 1073741824
gc-max-store-size-linux: 1G
# do purge caches
purge: true
# purge all versions of the cache
purge-prefixes: build-${{ runner.os }}-
# created more than this number of seconds ago
# relative to the start of the `Post Restore and save Nix store` phase
purge-created: 0
# except any version with the key that is the same as the `primary-key`
purge-primary-key: never
- name: Prefetch latest MoonBit
id: fetch_toolchains
timeout-minutes: 10
run: ./scripts/fetch_toolchains.sh
- name: Prefetch latest Moon Patched Deps
if: steps.fetch_toolchains.outputs.skipped != 'true'
timeout-minutes: 10
run: ./lib/moon-patched/update.sh
env:
REVISION: ${{ steps.fetch_toolchains.outputs.moon_revision }}
- name: Check and commit changes (versions)
id: commit_version
if: steps.fetch_toolchains.outputs.skipped != 'true'
continue-on-error: true
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add versions
git add lib/moon-patched/deps_versions.json
git commit -m "versions: update"
- name: Push version changes
if: steps.commit_version.outcome == 'success'
uses: ad-m/github-push-action@master
with:
branch: ${{ github.ref }}
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Check if tag exists
id: check_tag
if: steps.commit_version.outcome == 'success'
run: |
TAG="${{ steps.fetch_toolchains.outputs.version }}"
if git fetch --tags && git tag | grep -q "^$TAG$"; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Release new version
if: steps.commit_version.outcome == 'success' && steps.check_tag.outputs.exists == 'false'
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.fetch_toolchains.outputs.version }}
immutableCreate: true
body: "New version ${{ steps.fetch_toolchains.outputs.version }} fetched from MoonBit."
artifacts: "moonbit-linux-x86_64.tar.gz, moonbit-darwin-aarch64.tar.gz, moonbit-core.tar.gz"