dependency #2773
This file contains hidden or 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: 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@v7 | |
| with: | |
| submodules: true | |
| - name: Use Node.js | |
| uses: actions/setup-node@v7 | |
| 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 | |
| - name: Prepare config and i18n | |
| run: | | |
| git clone https://github.com/mirrorz-org/mirrorz-config.git src/config | |
| yarn ${{ matrix.build_type }}_env | |
| - name: Install dependencies | |
| run: yarn --frozen-lockfile | |
| - name: Build | |
| run: | | |
| yarn build | |
| mkdir -p drop | |
| tar -czf drop/dist-${{ matrix.build_type }}.tar.gz dist | |
| - name: Upload dist package as artifact | |
| uses: actions/upload-artifact@v7 | |
| 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@v7 | |
| with: | |
| submodules: true | |
| - name: Use Node.js | |
| uses: actions/setup-node@v7 | |
| 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@v8 | |
| 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@v7 | |
| 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@v7 | |
| 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@v7 | |
| with: | |
| submodules: true | |
| - name: Download dist package | |
| uses: actions/download-artifact@v8 | |
| 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 "bot@mirrorz.org" | |
| 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 |