diff --git a/.github/actions/custom-surge-preview/action.yml b/.github/actions/custom-surge-preview/action.yml new file mode 100644 index 0000000000..02970e97c0 --- /dev/null +++ b/.github/actions/custom-surge-preview/action.yml @@ -0,0 +1,38 @@ +name: 'Custom surge preview' +description: 'Simplify usage of surge-preview' +inputs: + build-preview-command: + description: 'The command to build the preview' + required: true + build-preview-dist: + description: 'The dist folder deployed to surge.sh' + required: true + github-token: + description: 'A token with `pull-requests: write` to let the surge-preview action create comments on pull requests' + required: true + surge-token: + description: 'A surge token to manage the deployment' + required: true + +runs: + using: 'composite' + steps: + - uses: bonitasoft/actions/packages/surge-preview-tools@v1.2.0 + id: surge-preview-tools + with: + surge-token: ${{ inputs.surge-token }} + - uses: actions/checkout@v3 + if: github.event.action != 'closed' + - name: Build Setup + uses: ./.github/actions/build-setup + if: github.event.action != 'closed' + - name: Manage surge preview + if: steps.surge-preview-tools.outputs.can-run-surge-command == 'true' + uses: afc163/surge-preview@v1 + with: + surge_token: ${{ inputs.surge-token }} + github_token: ${{ inputs.github-token }} + dist: ${{ inputs.build-preview-dist }} + failOnError: true + teardown: 'true' + build: ${{ inputs.build-preview-command }} diff --git a/.github/workflows/generate-demo-preview.yml b/.github/workflows/generate-demo-preview.yml index 06aed95047..95c641951a 100644 --- a/.github/workflows/generate-demo-preview.yml +++ b/.github/workflows/generate-demo-preview.yml @@ -20,41 +20,16 @@ on: - 'tsconfig.json' jobs: - # inspired from https://github.com/process-analytics/github-actions-playground/pull/23 - check_secrets: - runs-on: ubuntu-20.04 - outputs: - is_SURGE_TOKEN_set: ${{ steps.secret_availability.outputs.is_SURGE_TOKEN_set }} - steps: - - name: Compute secrets availability - id: secret_availability - env: - SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} - run: | - echo "is_SURGE_TOKEN_set: ${{ env.SURGE_TOKEN != '' }}" - echo "::set-output name=is_SURGE_TOKEN_set::${{ env.SURGE_TOKEN != '' }}" - - demo_preview: - needs: [check_secrets] - if: needs.check_secrets.outputs.is_SURGE_TOKEN_set == 'true' + demo_preview: # keep unique across jobs using surge preview (preview url and PR comment id) runs-on: ubuntu-20.04 permissions: - # surge-preview: PR comments - pull-requests: write + pull-requests: write # surge-preview: PR comments steps: - - uses: actions/checkout@v3 - if: github.event.action != 'closed' - - name: Build Setup - uses: ./.github/actions/build-setup - if: github.event.action != 'closed' - - name: Publish Demo preview - id: publish_demo_preview - uses: afc163/surge-preview@v1 + - uses: actions/checkout@v3 # access to the local action + - name: surge preview + uses: ./.github/actions/custom-surge-preview with: - surge_token: ${{ secrets.SURGE_TOKEN }} - github_token: ${{ secrets.GITHUB_TOKEN }} - dist: build/demo - failOnError: true - teardown: 'true' - build: | - npm run demo + build-preview-command: npm run demo + build-preview-dist: build/demo + github-token: ${{ secrets.GITHUB_TOKEN }} + surge-token: ${{ secrets.SURGE_TOKEN }} diff --git a/.github/workflows/generate-documentation.yml b/.github/workflows/generate-documentation.yml index a6e2bc2fb5..4aa283576d 100644 --- a/.github/workflows/generate-documentation.yml +++ b/.github/workflows/generate-documentation.yml @@ -30,45 +30,20 @@ on: - 'typedoc.json' jobs: - # inspired from https://github.com/process-analytics/github-actions-playground/pull/23 - check_secrets: + doc_preview: # keep unique across jobs using surge preview (preview url and PR comment id) if: github.event_name == 'pull_request' runs-on: ubuntu-20.04 - outputs: - is_SURGE_TOKEN_set: ${{ steps.secret_availability.outputs.is_SURGE_TOKEN_set }} - steps: - - name: Compute secrets availability - id: secret_availability - env: - SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} - run: | - echo "is_SURGE_TOKEN_set: ${{ env.SURGE_TOKEN != '' }}" - echo "::set-output name=is_SURGE_TOKEN_set::${{ env.SURGE_TOKEN != '' }}" - - doc_preview: - needs: [check_secrets] - if: github.event_name == 'pull_request' && needs.check_secrets.outputs.is_SURGE_TOKEN_set == 'true' - runs-on: ubuntu-20.04 permissions: - # surge-preview: PR comments - pull-requests: write + pull-requests: write # surge-preview: PR comments steps: - - uses: actions/checkout@v3 - if: github.event.action != 'closed' - - name: Build Setup - uses: ./.github/actions/build-setup - if: github.event.action != 'closed' - - name: Publish preview - id: publish_preview - uses: afc163/surge-preview@v1 + - uses: actions/checkout@v3 # access to the local action + - name: surge preview + uses: ./.github/actions/custom-surge-preview with: - surge_token: ${{ secrets.SURGE_TOKEN }} - github_token: ${{ secrets.GITHUB_TOKEN }} - dist: build/docs - failOnError: true - teardown: 'true' - build: | - npm run docs + build-preview-command: npm run docs + build-preview-dist: build/docs + github-token: ${{ secrets.GITHUB_TOKEN }} + surge-token: ${{ secrets.SURGE_TOKEN }} generate_doc: if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.event.ref == 'refs/heads/master' @@ -90,8 +65,7 @@ jobs: runs-on: ubuntu-20.04 needs: generate_doc permissions: - # Push to gh-pages - contents: write + contents: write # Push to gh-pages steps: - name: Download uses: actions/download-artifact@v3