Skip to content

dependency

dependency #1938

Workflow file for this run

name: Yarn build and Publish to another repo
on:
workflow_dispatch:
repository_dispatch:
types: [dependency]
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
build_type: [mirrorz, cernet]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Prepare static
run: |
git clone https://github.com/mirrorz-org/mirrorz-json-legacy.git static/json/json-legacy
mv static/json/json-legacy/data static/json/legacy
rm -rf static/json/json-legacy
git clone https://github.com/mirrorz-org/mirrorz-json-site.git static/json/site
- name: Prepare parser, config, i18n, oh-my-mirrorz
run: |
git clone https://github.com/mirrorz-org/mirrorz-parser.git src/parser
git clone https://github.com/mirrorz-org/mirrorz-config.git src/config
git clone https://github.com/mirrorz-org/mirrorz-i18n.git src/i18n
yarn ${{ matrix.build_type }}_env
git clone https://github.com/mirrorz-org/oh-my-mirrorz.git scripts/oh-my-mirrorz
- name: Prepare legacy
run: |
git clone https://github.com/mirrorz-org/mirrorz-legacy.git legacy
yarn legacy_env
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Install legacy dependencies
run: |
cd legacy
yarn --frozen-lockfile
cd ..
- name: Build
run: |
yarn build
yarn legacy_build
yarn ohmymirrorz_build
mkdir -p drop
tar -czf drop/dist-${{ matrix.build_type }}.tar.gz dist
- name: Upload dist package as artifact
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.build_type }}
path: drop/dist-${{ matrix.build_type }}.tar.gz
retention-days: 3
screenshots:
name: Visual diff
if: ${{ false }} # TODO: disable for now. Should provide a mock env
runs-on: ubuntu-latest
needs:
- build
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '14'
- name: Install dependencies
run: |
yarn --frozen-lockfile
npx playwright install-deps
npx playwright install
- name: Download dist package
uses: actions/download-artifact@v4
with:
name: dist
- name: Unzip dist package
run: |
tar xzf dist.tar.gz
- name: Update snapshot baseline
if: ${{ github.ref == 'refs/heads/master' }}
run: |
yarn test --update-snapshots
- name: Upload screenshot baseline as artifacts
if: ${{ github.ref == 'refs/heads/master' }}
uses: actions/upload-artifact@v4
with:
name: screenshot-baseline
path: |
tests/*-snapshots
- name: Download baseline and take screenshots
if: ${{ github.ref != 'refs/heads/master' }}
run: |
yarn download-snapshot-baseline snapshot-baseline.zip
unzip -o snapshot-baseline.zip -d tests
yarn test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload screenshot differences as artifacts
if: ${{ github.ref != 'refs/heads/master' && always() }}
uses: actions/upload-artifact@v4
with:
name: screenshots
path: |
tests/*-snapshots
test-results
retention-days: 3
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
build_type: [mirrorz, cernet]
if: ${{ github.ref == 'refs/heads/master' }}
needs:
- build
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Download dist package
uses: actions/download-artifact@v4
with:
name: dist-${{ matrix.build_type }}
- name: Commit and publish
env:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
PUBLISH_REPOSITORY: ${{ secrets.PUBLISH_REPOSITORY }}
run: |
tar xzf dist-${{ matrix.build_type }}.tar.gz
remote_repo="https://x-access-token:${ACCESS_TOKEN}@github.com/${PUBLISH_REPOSITORY}.git"
if [[ "${{ matrix.build_type }}" == "mirrorz" ]]; then
remote_branch="master"
else
remote_branch="cernet"
fi
git_commit_id=$(git rev-parse --short HEAD)
mkdir _site_remote && cd _site_remote
git init
git config user.name "Mirrorz Bot"
git config user.email "[email protected]"
git remote add origin $remote_repo
git pull origin $remote_branch
git checkout $remote_branch
git rm -rf .
git clean -fxd
cp -ar ../dist/* ./
touch .nojekyll
git add .
git commit -m "Github Action auto build for https://github.com/mirrorz-org/mirrorz/commit/${git_commit_id}" --allow-empty
git push -u origin $remote_branch