|
| 1 | +name: Build distribution theme |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - "**" |
| 9 | + - "!**.md" |
| 10 | + release: |
| 11 | + types: |
| 12 | + - created |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v2 |
| 19 | + with: |
| 20 | + submodules: false |
| 21 | + - name: Set up Node.js |
| 22 | + uses: actions/setup-node@v3 |
| 23 | + with: |
| 24 | + node-version: 16 |
| 25 | + |
| 26 | + name: Install pnpm |
| 27 | + id: install-pnpm |
| 28 | + with: |
| 29 | + version: 7 |
| 30 | + run_install: false |
| 31 | + - name: Get pnpm store directory |
| 32 | + id: pnpm-cache |
| 33 | + run: | |
| 34 | + echo "::set-output name=pnpm_cache_dir::$(pnpm store path)" |
| 35 | + - uses: actions/cache@v3 |
| 36 | + name: Setup pnpm cache |
| 37 | + with: |
| 38 | + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} |
| 39 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('./pnpm-lock.yaml') }} |
| 40 | + restore-keys: | |
| 41 | + ${{ runner.os }}-pnpm-store- |
| 42 | + - name: Install dependencies |
| 43 | + run: | |
| 44 | + pnpm install |
| 45 | + - name: Build distribution |
| 46 | + run: | |
| 47 | + pnpm build |
| 48 | + - name: Inject slug/short variables |
| 49 | + uses: rlespinasse/github-slug-action@v4 |
| 50 | + - name: Compress zip |
| 51 | + run: | |
| 52 | + PACKAGE_VERSION=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' package.json) |
| 53 | + PACKAGE_NAME=${GITHUB_REPOSITORY_NAME_PART_SLUG} |
| 54 | + PRE_ZIP_FOLDER=${PACKAGE_NAME}-${PACKAGE_VERSION} |
| 55 | + ARTIFACT_NAME=${PRE_ZIP_FOLDER}.zip |
| 56 | + ARTIFACT_PATHNAME=dist/${ARTIFACT_NAME} |
| 57 | + echo "${PACKAGE_NAME} version $PACKAGE_VERSION" |
| 58 | + echo "Artifact name: ${ARTIFACT_NAME}" |
| 59 | + echo "Artifact pathname: ${ARTIFACT_PATHNAME}" |
| 60 | + echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_ENV |
| 61 | + echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV |
| 62 | + echo "ARTIFACT_PATHNAME=${ARTIFACT_PATHNAME}" >> $GITHUB_ENV |
| 63 | + echo "RELEASE_ID=${{ github.event.release.id }}" >> $GITHUB_ENV |
| 64 | + mkdir $PRE_ZIP_FOLDER |
| 65 | + mkdir dist |
| 66 | + cp -r theme.yaml settings.yaml annotation-settings.yaml templates $PRE_ZIP_FOLDER/ |
| 67 | + zip -r $ARTIFACT_PATHNAME $PRE_ZIP_FOLDER |
| 68 | + - name: Upload artifact |
| 69 | + uses: actions/upload-artifact@v2 |
| 70 | + with: |
| 71 | + name: ${{ env.ARTIFACT_NAME }} |
| 72 | + path: | |
| 73 | + dist/*.zip |
| 74 | + retention-days: 7 |
| 75 | + |
| 76 | + github-release: |
| 77 | + runs-on: ubuntu-latest |
| 78 | + if: github.event_name == 'release' |
| 79 | + steps: |
| 80 | + - uses: actions/checkout@v2 |
| 81 | + with: |
| 82 | + submodules: false |
| 83 | + - name: Set up Node.js |
| 84 | + uses: actions/setup-node@v3 |
| 85 | + with: |
| 86 | + node-version: 16 |
| 87 | + |
| 88 | + name: Install pnpm |
| 89 | + id: install-pnpm |
| 90 | + with: |
| 91 | + version: 7 |
| 92 | + run_install: false |
| 93 | + - name: Get pnpm store directory |
| 94 | + id: pnpm-cache |
| 95 | + run: | |
| 96 | + echo "::set-output name=pnpm_cache_dir::$(pnpm store path)" |
| 97 | + - uses: actions/cache@v3 |
| 98 | + name: Setup pnpm cache |
| 99 | + with: |
| 100 | + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} |
| 101 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('./pnpm-lock.yaml') }} |
| 102 | + restore-keys: | |
| 103 | + ${{ runner.os }}-pnpm-store- |
| 104 | + - name: Install dependencies |
| 105 | + run: | |
| 106 | + pnpm install |
| 107 | + - name: Build distribution |
| 108 | + run: | |
| 109 | + pnpm build |
| 110 | + - name: Inject slug/short variables |
| 111 | + uses: rlespinasse/github-slug-action@v4 |
| 112 | + - name: Compress zip |
| 113 | + run: | |
| 114 | + PACKAGE_VERSION=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' package.json) |
| 115 | + PACKAGE_NAME=${GITHUB_REPOSITORY_NAME_PART_SLUG} |
| 116 | + PRE_ZIP_FOLDER=${PACKAGE_NAME}-${PACKAGE_VERSION} |
| 117 | + ARTIFACT_NAME=${PRE_ZIP_FOLDER}.zip |
| 118 | + ARTIFACT_PATHNAME=dist/${ARTIFACT_NAME} |
| 119 | + echo "${PACKAGE_NAME} version $PACKAGE_VERSION" |
| 120 | + echo "Artifact name: ${ARTIFACT_NAME}" |
| 121 | + echo "Artifact pathname: ${ARTIFACT_PATHNAME}" |
| 122 | + echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_ENV |
| 123 | + echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV |
| 124 | + echo "ARTIFACT_PATHNAME=${ARTIFACT_PATHNAME}" >> $GITHUB_ENV |
| 125 | + echo "RELEASE_ID=${{ github.event.release.id }}" >> $GITHUB_ENV |
| 126 | + mkdir $PRE_ZIP_FOLDER |
| 127 | + mkdir dist |
| 128 | + cp -r theme.yaml settings.yaml annotation-settings.yaml templates $PRE_ZIP_FOLDER/ |
| 129 | + zip -r $ARTIFACT_PATHNAME $PRE_ZIP_FOLDER |
| 130 | + - name: Upload a release asset |
| 131 | + uses: actions/github-script@v2 |
| 132 | + with: |
| 133 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 134 | + script: | |
| 135 | + const fs = require('fs').promises; |
| 136 | + const { repo: { owner, repo }, sha } = context; |
| 137 | + console.log({ owner, repo, sha }); |
| 138 | + const releaseId = process.env.RELEASE_ID |
| 139 | + const artifactPathName = process.env.ARTIFACT_PATHNAME |
| 140 | + const artifactName = process.env.ARTIFACT_NAME |
| 141 | + console.log('Releasing', releaseId, artifactPathName, artifactName) |
| 142 | + await github.repos.uploadReleaseAsset({ |
| 143 | + owner, repo, |
| 144 | + release_id: releaseId, |
| 145 | + name: artifactName, |
| 146 | + data: await fs.readFile(artifactPathName) |
| 147 | + }); |
0 commit comments