yacd/.github/workflows/push.yml

175 lines
5.4 KiB
YAML
Raw Normal View History

on: [push]
name: Deploy workflow
2022-05-08 22:47:42 +08:00
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true
jobs:
install:
2022-08-27 14:45:24 +08:00
runs-on: ubuntu-latest
2023-01-18 16:32:06 +08:00
permissions:
contents: write
2023-01-30 22:09:39 +08:00
# https://github.com/actions/deploy-pages
pages: write
id-token: write
strategy:
matrix:
2022-03-06 17:32:23 +08:00
node-version: [16.x]
steps:
2022-05-08 23:38:02 +08:00
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
2022-05-08 14:37:00 +08:00
- name: Cache pnpm modules
2022-05-08 23:38:02 +08:00
uses: actions/cache@v3
2019-11-14 00:31:03 +08:00
with:
2022-05-08 14:37:00 +08:00
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
2019-11-14 00:31:03 +08:00
restore-keys: |
2022-05-08 14:37:00 +08:00
${{ runner.os }}-
2022-11-07 16:56:06 +08:00
- uses: pnpm/action-setup@v2.2.4
2022-05-08 14:37:00 +08:00
with:
version: 7
run_install: true
2019-11-14 00:31:03 +08:00
- name: Lint
2022-05-08 14:37:00 +08:00
run: pnpm lint
2023-01-30 20:52:43 +08:00
- name: Set git commit sha
id: revparse
run: |
echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Build
2022-05-08 14:37:00 +08:00
run: pnpm build
- name: Create Release
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: true
prerelease: false
- name: Create Tar Ball
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')
2020-11-24 19:43:14 +08:00
run: tar cJf yacd.tar.xz public
- name: Upload Release Asset
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./yacd.tar.xz
asset_name: yacd.tar.xz
asset_content_type: application/x-gzip
- name: Push to gh-pages
if: github.event_name == 'push' && (startsWith(github.event.ref, 'refs/tags/') || github.event.ref == 'refs/heads/publish')
env:
2023-01-30 21:52:35 +08:00
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PUBLISH_DIR: public
BRANCH: gh-pages
run: |
cd $PUBLISH_DIR
ls -l
git init
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@noreply.github.com"
2022-09-15 14:51:43 +08:00
touch .nojekyll
git add .
git status
git commit -m "Push to gh-pages"
git push -f https://$GITHUB_ACTOR:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:$BRANCH
2020-08-01 20:49:00 +08:00
- name: Send Notification
uses: haishanh/actions-telegram-notification@v1
if: ${{ always() }}
2020-08-01 20:49:00 +08:00
with:
notification-token: ${{ secrets.TG_NOTIFICATION_TOKEN }}
job-status: ${{ job.status }}
docker:
needs: install
2022-08-27 14:45:24 +08:00
runs-on: ubuntu-latest
if: github.event_name == 'push' && (startsWith(github.event.ref, 'refs/tags/') || startsWith(github.event.ref, 'refs/heads/v0.') || github.event.ref == 'refs/heads/master' || github.event.ref == 'refs/heads/test')
steps:
2022-05-08 23:38:02 +08:00
- uses: actions/checkout@v3
2023-01-30 20:52:43 +08:00
- name: Set git commit sha
id: revparse
run: |
echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
2020-11-14 14:57:49 +08:00
2021-08-01 18:30:13 +08:00
- name: Cache Docker layers
2022-05-08 23:38:02 +08:00
uses: actions/cache@v3
2021-08-01 18:30:13 +08:00
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
2020-11-14 14:57:49 +08:00
- name: Docker meta
id: docker_meta
2022-05-08 23:38:02 +08:00
uses: docker/metadata-action@v4
2020-11-14 14:57:49 +08:00
with:
images: haishanh/yacd
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v1.2.0
2020-11-14 14:57:49 +08:00
- name: Set up Docker Buildx
id: buildx
2022-05-08 23:38:02 +08:00
uses: docker/setup-buildx-action@v2
with:
version: latest
2020-11-14 14:57:49 +08:00
- name: Builder instance name
run: echo ${{ steps.buildx.outputs.name }}
- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
2020-11-14 14:57:49 +08:00
- name: Login to Docker Hub
2022-05-08 23:38:02 +08:00
uses: docker/login-action@v2
2020-11-14 14:57:49 +08:00
with:
username: ${{ github.actor }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
2022-03-06 17:32:23 +08:00
- name: Login to GHCR
2022-05-08 23:38:02 +08:00
uses: docker/login-action@v2
2022-03-06 17:32:23 +08:00
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
2020-11-14 14:57:49 +08:00
- name: Build and push
2021-08-01 18:30:13 +08:00
id: docker_build
2022-05-08 23:38:02 +08:00
uses: docker/build-push-action@v3
2020-11-14 14:57:49 +08:00
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
2022-03-06 17:32:23 +08:00
tags: ${{ steps.docker_meta.outputs.tags }},ghcr.io/${{ steps.docker_meta.outputs.tags }}
2020-11-14 14:57:49 +08:00
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha
2023-01-30 20:52:43 +08:00
build-args: |
COMMIT_HASH=${{ env.COMMIT_HASH }}
2021-08-01 18:30:13 +08:00
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
2020-11-14 14:57:49 +08:00
- name: Send Notification
uses: haishanh/actions-telegram-notification@v1
if: ${{ always() }}
with:
notification-token: ${{ secrets.TG_NOTIFICATION_TOKEN }}
job-status: ${{ job.status }}