yacd/.github/workflows/push.yml

156 lines
4.8 KiB
YAML
Raw Normal View History

on: [push]
name: Deploy workflow
jobs:
install:
runs-on: ubuntu-20.04
strategy:
matrix:
2022-03-06 17:32:23 +08:00
node-version: [16.x]
steps:
2022-03-06 17:32:23 +08:00
- uses: actions/checkout@v3.0.0
- 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
uses: actions/cache@v2
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 }}-
- uses: pnpm/action-setup@v2.2.1
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
- 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:
GITHUB_TOKEN: ${{ secrets.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"
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
runs-on: ubuntu-20.04
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-03-06 17:32:23 +08:00
- uses: actions/checkout@v3.0.0
2020-11-14 14:57:49 +08:00
2021-08-01 18:30:13 +08:00
- name: Cache Docker layers
uses: actions/cache@v2.1.7
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
uses: docker/metadata-action@v3.6.2
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
uses: docker/setup-buildx-action@v1
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-03-06 17:32:23 +08:00
uses: docker/login-action@v1.14.1
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
uses: docker/login-action@v1.10.0
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
2020-11-14 14:57:49 +08:00
uses: docker/build-push-action@v2
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
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 }}