Nightly Build #29
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: Nightly Build | |
on: | |
schedule: | |
- cron: "0 10 * * *" | |
workflow_dispatch: | |
permissions: | |
contents: write | |
# packages: write | |
# issues: write | |
jobs: | |
check_need_build: | |
runs-on: ubuntu-latest | |
outputs: | |
skip: ${{ steps.check.outputs.skip }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Check Need Build | |
id: check | |
run: | | |
if [[ "$(git log --since='24 hours ago' | wc -l)" -eq 0 ]] || \ | |
[[ "$GITHUB_REPOSITORY" != "Redish101/reblog" ]]; then | |
echo "skip=true" >> $GITHUB_OUTPUT | |
else | |
echo "skip=false" >> $GITHUB_OUTPUT | |
fi | |
test: | |
runs-on: ubuntu-latest | |
needs: check_need_build | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.22 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
- name: Setup PNPM | |
uses: pnpm/action-setup@v4 | |
with: | |
version: 8.11.0 | |
- name: Install Dependencies | |
run: make install-dev | |
- name: Build | |
run: make | |
- name: Test | |
run: make test | |
build: | |
needs: [check_need_build, test] | |
if: ${{ needs.check_need_build.outputs.skip != 'true' }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
arch: [amd64, arm64] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Cache Turbo Build Setup | |
uses: actions/cache@v4 | |
with: | |
path: .turbo | |
key: ${{ runner.os }}-turbo- | |
restore-keys: | | |
${{ runner.os }}-turbo- | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.22 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
- name: Setup PNPM | |
uses: pnpm/action-setup@v4 | |
with: | |
version: 8.11.0 | |
- name: Install Dependencies | |
run: make install-dev | |
- name: Set GOARCH for AMD64 | |
if: matrix.arch == 'amd64' | |
run: echo "GOARCH=amd64" >> $GITHUB_ENV | |
- name: Set GOARCH for ARM64 | |
if: matrix.arch == 'arm64' | |
run: echo "GOARCH=arm64" >> $GITHUB_ENV | |
- name: Build | |
run: make VERSION=nightly | |
- name: Rename Binary | |
run: | | |
mv bin/reblog bin/reblog-${{ matrix.os }}-${{ matrix.arch }} | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.os }}-${{ matrix.arch }} | |
path: bin/reblog-${{ matrix.os }}-${{ matrix.arch }} | |
release: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: /tmp/artifacts/ | |
- name: Create tag and push | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config user.name github-actions[bot] | |
git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
gh release delete nightly --yes || true | |
git push origin :refs/tags/nightly || true | |
git tag -f nightly | |
git push -f origin nightly | |
- 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) | |
MD_FILE="/tmp/changelog.md" | |
echo -e "$CHANGELOG" > $MD_FILE | |
echo -e "\n> [!NOTE]\n" \ | |
"> Nightly Build由ci在每晚自动从最新源代码构建并发布,仅作为预览使用,不保证可用性,不建议在生产环境下使用。" >> $MD_FILE | |
- name: Get Files | |
run: | | |
cd /tmp/artifacts | |
FILES=$(find ${DIST_DIR} -type f -exec readlink -f {} \;) | |
echo -e "RELEASE_FILES<<EOF" >> $GITHUB_ENV | |
echo -e "$FILES" >> $GITHUB_ENV | |
echo -e "EOF" >> $GITHUB_ENV | |
- name: Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
prerelease: true | |
tag_name: nightly | |
name: Nightly Build | |
body_path: /tmp/changelog.md | |
files: ${{ env.RELEASE_FILES }} | |
draft: false |