yacd/.github/workflows/push.yml

107 lines
3.7 KiB
YAML
Raw Normal View History

on: [push]
name: Deploy workflow
jobs:
install:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [14.x]
steps:
2020-03-05 09:53:41 +08:00
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2.1.2
with:
node-version: ${{ matrix.node-version }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
2019-11-14 00:31:03 +08:00
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
2019-11-14 00:31:03 +08:00
restore-keys: |
${{ runner.os }}-yarn-
2019-11-14 00:31:03 +08:00
- name: Install
run: yarn
- name: Lint
run: yarn lint
- name: Build
run: yarn build
##### gh-pages
- 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/')
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: linux/amd64,linux/arm/v7,linux/arm64
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
- name: Builder instance name
run: echo ${{ steps.buildx.outputs.name }}
- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: Log in to Docker Hub
env:
DOCKER_USERNAME: ${{ github.actor }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
run: |
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin
- name: Build and push Docker image
env:
DOCKER_USERNAME: ${{ github.actor }}
DOCKER_IMAGE_PLATFORM: linux/amd64,linux/arm/v7,linux/arm64
REPOSITORY_NAME: ${{ github.repository }}
run: |
IFS='/' read -ra repository_name_array <<<"$REPOSITORY_NAME"
DOCKER_IMAGE_NAME=$(echo $DOCKER_USERNAME/${repository_name_array[1]} | tr '[:upper:]' '[:lower:]')
DOCKER_IMAGE_VERSION=${GITHUB_REF#refs/*/}
docker buildx build \
--platform "$DOCKER_IMAGE_PLATFORM" \
--output "type=image,push=true" \
--tag "$DOCKER_IMAGE_NAME":"$DOCKER_IMAGE_VERSION" \
--tag "$DOCKER_IMAGE_NAME":latest \
--file ./Dockerfile .
- name: Send Notification
uses: haishanh/actions-telegram-notification@v1
if: ${{ always() }}
with:
notification-token: ${{ secrets.TG_NOTIFICATION_TOKEN }}
job-status: ${{ job.status }}