Skip to content

Build and Release

Build and Release #61

Workflow file for this run

name: Build and Release
on:
push:
branches:
- "release/v*.*.*"
tags-ignore:
- "v*.*.*-*"
workflow_dispatch:
inputs:
memos-tag:
description: |
Upstream tag to build.
The action will fail if a matching tag already exists on this repository.
required: false
type: string
memos-release:
description: |
Upstream release to build.
The action will fail if a matching tag already exists on this repository.
required: false
type: string
env:
DOCKER_PLATFORMS: |
linux/386
linux/amd64
linux/amd64/v2
linux/amd64/v3
linux/arm/v5
linux/arm/v6
linux/arm/v7
linux/arm64
linux/ppc64le
linux/riscv64
linux/s390x
QEMU_PLATFORMS: |
linux/386
linux/amd64
linux/arm/v6
linux/arm/v7
linux/arm64
linux/ppc64le
linux/riscv64
linux/s390x
# Variables set by scripts/ci.py
GORELEASER_CURRENT_TAG: "[not set]"
BUILD_VERSION: "[not set]"
CACHE_KEY: "[not set]"
jobs:
front-end:
name: Build front-end
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
fetch-depth: 0
# setup deps
- name: Setup Task
uses: jaxxstorm/action-install-gh-release@71d17cb091aa850acb2a1a4cf87258d183eb941b
with:
repo: go-task/task
cache: enable
tag: "v3.34.1"
- name: Setup pnpm
uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d
with:
version: 8
- name: Setup Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version: 20
cache: pnpm
cache-dependency-path: "memos/web/pnpm-lock.yaml"
# /setup deps
# When running the workflow manually, allows to build a specific tag or release.
# If the build is triggered by other events, will build whatever is already commited to the subtree.
- if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.memos-release == '' && github.event.inputs.memos-tag != '' }}
name: Pull usememos/memos:tags/${{ inputs.memos-tag }} to subtree
run: python scripts/ci.py pull-subtree --branch=tags/${{ inputs.memos-tag }}
- if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.memos-tag == '' && github.event.inputs.memos-release != '' }}
name: Pull usememos/memos:releases/${{ inputs.memos-release }} to subtree
run: python scripts/ci.py pull-subtree --branch=heads/release/${{ inputs.memos-release }}
# Run after subtree pull, in case version.go changed.
- name: Setup environment variables
run: python scripts/ci.py setup-env
- name: Cache front-end build
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2
with:
path: |
build/frontend
.task/checksum/build-frontend
key: |
frontend-${{env.BUILD_VERSION}}-${{ env.CACHE_KEY }}
restore-keys: |
frontend-${{env.BUILD_VERSION}}-
- name: Build front-end
run: task build:frontend
- name: Upload front-end artifact
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
with:
name: frontend_${{env.BUILD_VERSION}}
compression-level: 9
if-no-files-found: error
path: |
build/frontend/
.task/checksum/build-frontend
goreleaser:
name: Build back-end and Release
runs-on: ubuntu-22.04
permissions:
actions: read # required by wait action
contents: write
discussions: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
fetch-depth: 0
# setup deps
- name: Setup Task
uses: jaxxstorm/action-install-gh-release@71d17cb091aa850acb2a1a4cf87258d183eb941b
with:
repo: go-task/task
cache: enable
tag: "v3.34.1"
- name: Setup buf
uses: bufbuild/buf-setup-action@88db93f5d74ffa329bb43e42aa95cd822697d214
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
version: 1.29.0
- name: Setup UPX
uses: crazy-max/ghaction-upx@0fc45e912669ba9e8fa2b430e97c8da2a632e29b
with:
install-only: true
- name: Setup Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version: ">=1.22"
check-latest: true
cache-dependency-path: memos/go.sum
# /setup deps
# When running the workflow manually, allows to build a specific tag or release.
# If the build is triggered by other events, will build whatever is already commited to the subtree.
- if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.memos-release == '' && github.event.inputs.memos-tag != '' }}
name: Pull usememos/memos:tags/${{ inputs.memos-tag }} to subtree
run: |
python scripts/ci.py pull-subtree --branch=tags/${{ inputs.memos-tag }}
python scripts/ci.py retag --tag=v${{ inputs.memos-tag }} --push
- if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.memos-tag == '' && github.event.inputs.memos-release != '' }}
name: Pull usememos/memos:releases/${{ inputs.memos-release }} to subtree
run: |
python scripts/ci.py pull-subtree --branch=heads/release/${{ inputs.memos-release }}
python scripts/ci.py retag --tag=${{ inputs.memos-release }} --push
# Run after subtree pull, in case version.go changed.
- name: Setup environment variables
run: python scripts/ci.py setup-env
### Front-end ###
- name: Wait for the front-end build to finish
uses: yogeshlonkar/wait-for-jobs@62dd636cfcd6eefad75887c78f1e1c291a8d13d2
with:
jobs: "Build front-end"
interval: "2000"
ttl: "10"
- name: Download front-end artifact
uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe
with:
name: frontend_${{env.BUILD_VERSION}}
### /Front-end ###
- name: go.mod tidy
run: task build:backend-tidy
- name: Generate protobuf-related code
run: task build:buf
- name: Build and release with Goreleaser
uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8
with:
distribution: goreleaser
version: v1.24
args: release --clean --timeout 60m
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
### Docker ###
- name: Rename goreleaser builds to the format expected by current Dockerfile
run: python scripts/ci.py rename-to-docker
- name: Setup QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3
with:
platforms: ${{ env.QEMU_PLATFORMS }}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226
with:
version: latest
install: true
platforms: ${{ env.DOCKER_PLATFORMS }}
- name: Log-in to Docker Hub
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
username: lincolnthalles
password: ${{ secrets.DOCKER_TOKEN }}
- name: Log-in to GitHub's Container registry
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: |
lincolnthalles/memos
ghcr.io/lincolnthalles/memos-builds
tags: |
type=raw,value=latest
type=semver,pattern={{version}},value=${{ env.BUILD_VERSION }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.BUILD_VERSION }}
- name: Build and Push Docker images
id: docker_build
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
with:
context: ./
file: ./docker/Dockerfile
platforms: ${{ env.DOCKER_PLATFORMS }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
### /Docker ###