Skip to content

Commit

Permalink
chore(ci/nightly): improve nightly build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
qwqcode committed Mar 15, 2024
1 parent 1ee3c41 commit c1f596c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ workflows:
branches:
ignore:
- gh-pages
- /release\/.+/
- nightly
104 changes: 50 additions & 54 deletions .github/workflows/build-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ jobs:
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 -d nightly
git push origin :refs/tags/nightly
git tag -f nightly
git checkout nightly
git push -f origin nightly
# https://github.com/docker/metadata-action
- name: Gen docker meta
id: meta
Expand Down Expand Up @@ -80,14 +92,14 @@ jobs:
run: |
make build-frontend
# https://github.com/docker/build-push-action
- name: Build Multi-Platform Docker Images and Push
- name: Build `linux/amd64` and Load locally
uses: docker/build-push-action@v5
with:
push: ${{ !inputs.dry_run }}
load: true # automatically load the single-platform build result to `docker images`
push: false
context: .
file: ./Dockerfile
platforms: ${{ env.PLATFORMS }}
platforms: 'linux/amd64'
build-args: ${{ env.DOCKER_BUILD_ARGS }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand All @@ -99,67 +111,37 @@ jobs:
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

- name: Build `linux/amd64` and Load locally
# 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:
load: true # automatically load the single-platform build result to `docker images`
push: false
push: true
context: .
file: ./Dockerfile
platforms: 'linux/amd64'
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
# cache-to: type=local,dest=/tmp/.buildx-cache-new

# Export docker image
- name: Export Docker Image
id: docker_image
run: |
FILENAME="docker_image_nigthly_$(date +'%Y%m%d')_linux_amd64.tar"
FILENAME="artalk_docker_nigthly_$(date +'%Y%m%d')_linux_amd64.tar"
docker save -o $FILENAME ${{ env.DOCKER_IMG }}
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
- name: Upload Docker Image
uses: actions/upload-artifact@v4
with:
name: "${{ steps.docker_image.outputs.filename }}"
path: "${{ steps.docker_image.outputs.filename }}"

# 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}\n" | cat - CHANGELOG.md > temp && mv temp CHANGELOG.md
- name: Upload Changelog
uses: actions/upload-artifact@v4
with:
name: CHANGELOG.md
path: CHANGELOG.md
compression-level: 0

# Frontend
- name: Pack frontend
id: pack_frontend
run: |
FILENAME="frontend_nigthly_$(date +'%Y%m%d').tar.gz"
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
- name: Upload frontend
uses: actions/upload-artifact@v4
with:
name: "${{ steps.pack_frontend.outputs.filename }}"
path: "${{ steps.pack_frontend.outputs.filename }}"
compression-level: 0

# App
- name: Pack app
id: pack_app
Expand All @@ -179,27 +161,41 @@ jobs:
tar -czf $FILENAME $DEST
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
- name: Upload App
uses: actions/upload-artifact@v4
with:
name: "${{ steps.pack_app.outputs.filename }}"
path: "${{ steps.pack_app.outputs.filename }}"
compression-level: 0
# 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: |
DIST_FILES: |-
${{ steps.docker_image.outputs.filename }}
${{ steps.pack_app.outputs.filename }}
${{ steps.pack_frontend.outputs.filename }}
CHANGELOG.md
run: |
sha256sum $DIST_FILES > checksums.txt
- name: Upload checksums.txt
uses: actions/upload-artifact@v4
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:
name: checksums.txt
path: checksums.txt
compression-level: 0
draft: ${{ inputs.dry_run }}
prerelease: true
tag_name: nightly
name: Nightly Version
body_path: release.md
files: |-
${{ env.DIST_FILES }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

- name: Handle Version Number
run: |
PREV_VERSION="$(git describe --tags --abbrev=0)"
PREV_VERSION="$(git describe --tags --abbrev=0 --match 'v*')"
NEXT_VERSION="v$(semver --increment ${{ inputs.semver }} ${PREV_VERSION})"
echo "PREV_VERSION=${PREV_VERSION}" >> $GITHUB_ENV
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: Test Docs

on:
push:
branches: ['*', '!release/*']
branches: ['*', '!release/*', '!nightly']
paths: ['docs/**']
tags-ignore: ['v*']
pull_request:
paths: ['docs/**']
branches: ['*', '!release/*']
branches: ['*', '!release/*', '!nightly']

jobs:
test_docs:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: Test Frontend

on:
push:
branches: ['*', '!release/*']
branches: ['*', '!release/*', '!nightly']
paths: ['ui/**']
tags-ignore: ['v*']
pull_request:
paths: ['ui/**']
branches: ['*', '!release/*']
branches: ['*', '!release/*', '!nightly']

jobs:
test_ui:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PKG_NAME := github.com/ArtalkJS/Artalk
BIN_NAME := ./bin/artalk
VERSION ?= $(shell git describe --tags --abbrev=0)
VERSION ?= $(shell git describe --tags --abbrev=0 --match 'v*')
COMMIT_HASH ?= $(shell git rev-parse --short HEAD)

HAS_RICHGO := $(shell which richgo)
Expand Down
2 changes: 1 addition & 1 deletion scripts/docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

IMAGE_NAME="artalk/artalk-go"
VERSION=$(git describe --tags --abbrev=0)
VERSION=$(git describe --tags --abbrev=0 --match 'v*')

if [[ $* == *--push* ]]
then
Expand Down

0 comments on commit c1f596c

Please sign in to comment.