Build Nightly (🧪 Dry-Run) #28
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 Nightly | |
run-name: Build Nightly ${{ inputs.dry_run && '(🧪 Dry-Run)' || '' }} | |
on: | |
schedule: | |
- cron: '0 10 * * *' | |
workflow_dispatch: | |
inputs: | |
dry_run: | |
description: 'Dry run' | |
type: boolean | |
default: true | |
env: | |
DOCKER_IMG: artalk/artalk-go | |
PLATFORMS: 'linux/amd64,linux/arm64,linux/arm/v7' | |
DOCKER_BUILD_ARGS: |- | |
SKIP_UI_BUILD=true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Check should run | |
if: github.event_name == 'schedule' | |
run: | | |
if [[ "$(git log --since='24 hours ago' | wc -l)" -eq 0 ]] || \ | |
[[ "$GITHUB_REPOSITORY" != "ArtalkJS/Artalk" ]]; then | |
echo "Skipping automatic run" | |
exit 78 | |
fi | |
- name: Create tag and push | |
run: | | |
git config user.name github-actions[bot] | |
git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
git tag -f nightly | |
git checkout nightly | |
git push -f origin nightly | |
# https://github.com/docker/metadata-action | |
- name: Gen docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
${{ env.DOCKER_IMG }} | |
tags: | | |
type=raw,value=nightly | |
# https://github.com/docker/login-action | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# https://github.com/docker/setup-qemu-action | |
- name: Setup QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: ${{ env.PLATFORMS }} | |
# https://github.com/docker/setup-buildx-action | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v3 | |
with: | |
version: 8 | |
- name: Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18.x | |
registry-url: https://registry.npmjs.org/ | |
cache: 'pnpm' | |
# Build UI outside of Docker to speed up cross-platform builds | |
- name: Build UI | |
run: | | |
make build-frontend | |
- name: Build `linux/amd64` and Load locally | |
uses: docker/build-push-action@v5 | |
with: | |
load: true # automatically load the single-platform build result to `docker images` | |
push: false | |
context: . | |
file: ./Dockerfile | |
platforms: 'linux/amd64' | |
build-args: ${{ env.DOCKER_BUILD_ARGS }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
- name: Move cache | |
run: | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
# https://github.com/docker/build-push-action | |
- name: Build Multi-Platform Docker Images and Push | |
uses: docker/build-push-action@v5 | |
if: ${{ !inputs.dry_run }} | |
with: | |
push: true | |
context: . | |
file: ./Dockerfile | |
platforms: ${{ env.PLATFORMS }} | |
build-args: ${{ env.DOCKER_BUILD_ARGS }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
# Export docker image | |
- name: Export Docker Image | |
id: docker_image | |
run: | | |
FILENAME="artalk_docker_nigthly_$(date +'%Y%m%d')_linux_amd64.tar" | |
docker save -o $FILENAME ${{ env.DOCKER_IMG }} | |
echo "filename=$FILENAME" >> $GITHUB_OUTPUT | |
# Frontend | |
- name: Pack frontend | |
id: pack_frontend | |
run: | | |
FILENAME="artalk_frontend_nigthly_$(date +'%Y%m%d').tar.gz" | |
PKG_FILE=$(pnpm pack -C ui/artalk --pack-destination ../.. | tail -n 1) | |
mv $PKG_FILE $FILENAME | |
echo "filename=$FILENAME" >> $GITHUB_OUTPUT | |
# App | |
- name: Pack app | |
id: pack_app | |
run: | | |
DEST="artalk_nigthly_$(date +'%Y%m%d')_linux_amd64" | |
FILENAME="$DEST.tar.gz" | |
mkdir -p $DEST | |
# bin file | |
docker run --rm --entrypoint cat ${{ env.DOCKER_IMG }} /artalk > "$DEST/artalk" | |
chmod +x "$DEST/artalk" | |
# doc file | |
cp conf/artalk.example.yml "$DEST/artalk.yml" | |
cp README.md LICENSE CHANGELOG.md "$DEST" | |
tar -czf $FILENAME $DEST | |
echo "filename=$FILENAME" >> $GITHUB_OUTPUT | |
# Generate CHANGELOG | |
- name: Generate Changelog | |
run: | | |
# install git-chglog | |
curl -sL $(curl -s https://api.github.com/repos/git-chglog/git-chglog/releases/latest \ | |
| grep -oP '"https://.+linux_amd64.tar.gz"' | tr -d \") | tar -C /usr/local/bin -xz git-chglog | |
CHANGELOG=$(git-chglog --config .github/chglog/config.yml --next-tag nightly nightly) | |
echo -e "$CHANGELOG" > release.md | |
echo -e "\n> ⚠️ This version is latest nightly build and is **NOT** the final released version. Please use it with caution." \ | |
"\n> 💡 Docker user can run \`docker pull artalk/artalk-go:nightly\` to get the nightly build." >> release.md | |
# checksums.txt | |
- name: Calculate checksums.txt | |
id: checksums | |
env: | |
DIST_FILES: |- | |
${{ steps.docker_image.outputs.filename }} | |
${{ steps.pack_app.outputs.filename }} | |
${{ steps.pack_frontend.outputs.filename }} | |
run: | | |
sha256sum $DIST_FILES > checksums.txt | |
echo -e "DIST_FILES<<EOF" >> $GITHUB_ENV | |
echo -e "$DIST_FILES" >> $GITHUB_ENV | |
echo -e "checksums.txt" >> $GITHUB_ENV | |
echo -e "EOF" >> $GITHUB_ENV | |
- name: Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
draft: ${{ inputs.dry_run }} | |
prerelease: true | |
tag_name: nightly | |
name: Nightly Version | |
body_path: release.md | |
files: |- | |
${{ env.DIST_FILES }} |