diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ca92183..3a95f1e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2.3.1 + uses: actions/checkout@v2.4.0 with: persist-credentials: false @@ -20,17 +20,7 @@ jobs: node-version: "12" check-latest: true - - name: Cache node modules - uses: actions/cache@v2 - id: cache - with: - path: node_modules - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - name: Install dependencies - if: steps.cache.outputs.cache-hit != 'true' run: npm install - name: Build diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml new file mode 100644 index 0000000..8928bd3 --- /dev/null +++ b/.github/workflows/preview-build.yml @@ -0,0 +1,37 @@ +name: Preview Build + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build-preview: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: build + run: | + npm install + npm run build:h5-netlify + + - name: upload dist artifact + uses: actions/upload-artifact@v2 + with: + name: dist + path: dist + retention-days: 5 + + - name: save PR number + if: ${{ always() }} + run: echo ${{ github.event.number }} > ./pr-id.txt + + - name: upload PR number + if: ${{ always() }} + uses: actions/upload-artifact@v2 + with: + name: pr + path: ./pr-id.txt diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml new file mode 100644 index 0000000..bd11003 --- /dev/null +++ b/.github/workflows/preview-deploy.yml @@ -0,0 +1,89 @@ +name: Preview Deploy + +on: + workflow_run: + workflows: ["Preview Build"] + types: + - completed + +jobs: + success: + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' + steps: + - name: download PR artifact + uses: dawidd6/action-download-artifact@v2 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + name: pr + + - name: save PR id + id: pr + run: echo "::set-output name=id::$( + + + body-include: '' + number: ${{ steps.pr.outputs.id }} + + - name: The job failed + if: ${{ failure() }} + uses: actions-cool/maintain-one-comment@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + body: | + 😭 Deploy PR Preview failed. + + + + + body-include: '' + number: ${{ steps.pr.outputs.id }} + + failed: + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' + steps: + - name: download PR artifact + uses: dawidd6/action-download-artifact@v2 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + name: pr + + - name: save PR id + id: pr + run: echo "::set-output name=id::$( + + + body-include: '' + number: ${{ steps.pr.outputs.id }} diff --git a/.github/workflows/preview-start.yml b/.github/workflows/preview-start.yml new file mode 100644 index 0000000..d790ff9 --- /dev/null +++ b/.github/workflows/preview-start.yml @@ -0,0 +1,17 @@ +name: Preview Start + +on: pull_request_target + +jobs: + preview: + runs-on: ubuntu-latest + steps: + - name: create + uses: actions-cool/maintain-one-comment@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + body: | + ⚡️ Deploying PR Preview... + + + body-include: '' diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml deleted file mode 100644 index 4a5a337..0000000 --- a/.github/workflows/preview.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Surge Preview - -on: - pull_request: - types: [opened, synchronize, reopened, closed] - -jobs: - preview: - runs-on: ubuntu-latest - if: github.repository == 'doocs/md' - steps: - - uses: actions/checkout@v2 - - uses: afc163/surge-preview@main - with: - surge_token: ${{ secrets.SURGE_TOKEN }} - github_token: ${{ secrets.GITHUB_TOKEN }} - dist: dist - build: | - npm install - npm run build:h5-netlify diff --git a/.gitignore b/.gitignore index 64b4fe9..9c387af 100644 --- a/.gitignore +++ b/.gitignore @@ -42,4 +42,6 @@ yarn-error.log* *.sw? # mockm -httpData \ No newline at end of file +httpData +public/upload/** +!public/upload/*.gitkeep \ No newline at end of file diff --git a/mm.config.js b/mm.config.js index 92ee749..13503ec 100644 --- a/mm.config.js +++ b/mm.config.js @@ -4,12 +4,22 @@ * @type {import('mockm/@types/config').Config} */ module.exports = (util) => { + const port = 9000 return { + port, api: { - '/upload'(req, res) { - res.json({ - msg: `上传成功`, - url: util.libObj.mockjs.mock(`@image`), + async '/upload'(req, res) { + const multiparty = await util.toolObj.generate.initPackge(`multiparty`) + const form = new multiparty.Form({ + uploadDir: `./public/upload/`, + }) + form.parse(req, (err, fields = [], files) => { + const path = files.file[0].path.replace(/\\/g, `/`) + const url = `http://127.0.0.1:${port}/${path}` + res.json({ + msg: `上传成功`, + url, + }) }) }, }, @@ -21,6 +31,10 @@ module.exports = (util) => { { // 测试 gitee/github 部署 fileDir: `./dist`, path: `/md`, + },, + { // 访问公共目录 + fileDir: `./public`, + path: `/public`, }, ], } diff --git a/public/upload/.gitkeep b/public/upload/.gitkeep new file mode 100644 index 0000000..e69de29