Skip to content

build and release

build and release #94

name: "build and release"
on:
pull_request:
push:
branches:
- "main"
schedule:
- cron: "00 01 * * *"
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create cache folder
run: |
sudo mkdir --parents /media/saved-cache
sudo chown -R "$(whoami)" /media/saved-cache
- name: Get cache
uses: actions/cache/restore@v4
with:
path: /media/saved-cache
key: docker-document-converter-build-cache-${{ github.run_id }}
restore-keys: docker-document-converter-build-cache
- name: Import cache
run: |
if (ls /media/saved-cache/*.tar.zst); then
docker run --pull always --rm \
--volume "/media/saved-cache:/media/saved-cache" \
--volume "docker-document-converter-build-cache:/media/build-cache" \
--workdir /media \
madebytimo/scripts \
compress.sh --decompress /media/saved-cache/*.tar.zst
rm /media/saved-cache/*.tar.zst
fi
- name: Set secrets and variables
run: |
mkdir data-local
echo "latest_version=$(git describe --tags --abbrev=0)" >> "$GITHUB_ENV"
echo "version=$(cat Version.txt)" >> "$GITHUB_ENV"
if [[ -n '${{ secrets.UNITY_LICENSE_FILE }}' ]]; then
echo '${{ secrets.UNITY_LICENSE_FILE }}' > data-local/unity-license.ulf
fi
if [[ -n '${{ secrets.DOCKER_REGISTRY_USERNAME }}' ]]; then
echo ${{ secrets.DOCKER_REGISTRY_PASSWORD }} | \
docker login --username ${{ secrets.DOCKER_REGISTRY_USERNAME }} \
--password-stdin ${{ secrets.DOCKER_REGISTRY_URL }}
fi
- name: Prepare environment
run: |
if [[ -f builder/docker.sh ]]; then
docker buildx create --use
fi
- name: Build
if: ${{ github.event_name != 'schedule'}}
run: |
if [[ ${{ github.ref }} == 'refs/heads/main' ]]; then
builder/build.sh --publish
else
builder/build.sh
fi
- name: Build update base
if: ${{ github.event_name == 'schedule'}}
run: builder/build.sh --publish --update-base
- name: Upload
uses: actions/upload-artifact@v4
with:
name: ${{ env.version }}
path: builds/*
- name: Release
if: ${{ github.ref == 'refs/heads/main' && env.latest_version != env.version }}
uses: softprops/action-gh-release@v2
with:
files: builds/*
tag_name: ${{ env.version }}
- name: Export cache
run: |
docker run --pull always --rm \
--volume "/media/saved-cache:/media/saved-cache" \
--volume "docker-document-converter-build-cache:/media/build-cache" \
madebytimo/scripts \
compress.sh --fast --output /media/saved-cache/build-cache /media/build-cache
sudo chown -R "$(whoami)" /media/saved-cache
- name: Delete old caches
env:
GH_TOKEN: ${{ github.token }}
run: |
for CACHE in $(gh cache list --key Factory-build-cache --ref ${{ github.ref}} \
| cut --fields 1); do
echo "Deleting cache \"$CACHE\"."
gh cache delete "$CACHE"
done
- name: Set cache
uses: actions/cache/save@v4
with:
path: /media/saved-cache
key: docker-document-converter-build-cache-${{ github.run_id }}