chore: revert action

This commit is contained in:
zernonia 2024-01-17 09:55:09 +08:00
parent fbd84e86ec
commit f962da4d50

View File

@ -11,21 +11,59 @@ on:
- dev - dev
paths: paths:
- 'apps/www/**' - 'apps/www/**'
pull_request_target:
types:
# When a created pull request from forked repo, it will be comment 'Should deploy to add label'
- opened
# When a labeled '🚀request-deploy' pull request from forked repo, it will be deploy to Cloudflare Pages
- labeled
paths:
- 'apps/www/**'
# Allows you to run this workflow manually from the Actions tab # Allows you to run this workflow manually from the Actions tab
# eslint-disable-next-line yml/no-empty-mapping-value # eslint-disable-next-line yml/no-empty-mapping-value
workflow_dispatch: workflow_dispatch:
permissions:
# default contents: read & write (in forked repos, only read)
contents: write
# default deployments: read & write (in forked repos, only read)
deployments: write
# default pull-requests: read & write (in forked repos, only read)
pull-requests: write
jobs: jobs:
publish: publish:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: env:
contents: read GITHUB_HEAD_REF: ${{ github.event.pull_request.head.sha }}
deployments: write
name: Publish to Cloudflare Pages name: Publish to Cloudflare Pages
# push event in main branch
# workflow_dispatch event
# pull_request event from not forked repo
# pull_request_target event with label "🚀request-deploy" from forked repo
if: ${{
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false) ||
(github.event_name == 'pull_request_target' &&
github.event.action == 'labeled' &&
github.event.pull_request.head.repo.fork == true &&
contains(github.event.label.name, '🚀request-deploy'))
}}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
fetch-depth: 0
- name: Print pull request head information
run: |
echo "Pull Request SHA: ${{ github.event.pull_request.head.sha }}"
echo "Pull Request Ref: ${{ github.event.pull_request.head.ref }}"
echo "Pull Request Env: ${{ env.GITHUB_HEAD_REF }}"
# Run a build step here # Run a build step here
- name: Setup Node.js environment - name: Setup Node.js environment
@ -60,25 +98,72 @@ jobs:
# Run a action to publish docs # Run a action to publish docs
- name: Publish to Cloudflare Pages - name: Publish to Cloudflare Pages
uses: unlike-ltd/github-actions-cloudflare-pages@v1.1.2 uses: cloudflare/pages-action@v1.5.0
with: with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: shadcn-vue projectName: shadcn-vue
directory: .vitepress/dist directory: .vitepress/dist
# Optional: Enable this if you want to have GitHub Deployments triggered
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
# Optional: Switch what branch you are publishing to.
# By default this will be the branch which triggered this workflow
branch: refs/pull/${{ github.event.number }}/merge
# Optional: Change the working directory
workingDirectory: apps/www
wranglerVersion: '3'
- name: Create PR comment
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
uses: mshick/add-pr-comment@v2
with:
message: |
### ⚡ Successfully Cloudflare Pages deployed!
| Name | Link |
| :--- | :--- |
| <span aria-hidden="true">🔨</span> Latest commit | ${{ github.event.pull_request.head.sha || github.sha }} |
| <span aria-hidden="true">🔍</span> Latest deploy log | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| <span aria-hidden="true">😎</span> Deploy Preview Url | [${{ steps.cloudflare-pages-deploy.outputs.url }}](${{ steps.cloudflare-pages-deploy.outputs.url }}) |
| <span aria-hidden="true">🌳</span> Environment | ${{ steps.cloudflare-pages-deploy.outputs.environment }} |
- name: Remove label
if: ${{ github.event_name == 'pull_request_target' && contains(github.event.label.name, '🚀request-deploy') }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
github-environment: ${{ github.event.pull_request.head.ref }} script: |
# uses: cloudflare/pages-action@v1.5.0 github.rest.issues.removeLabel({
# with: issue_number: context.issue.number,
# apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} owner: context.repo.owner,
# accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} repo: context.repo.repo,
# projectName: shadcn-vue name: ['🚀request-deploy']
# directory: .vitepress/dist })
# # Optional: Enable this if you want to have GitHub Deployments triggered
# gitHubToken: ${{ secrets.GITHUB_TOKEN }} # Comment on PR from the fork
# # Optional: Switch what branch you are publishing to. comment:
# # By default this will be the branch which triggered this workflow name: Comment
# branch: refs/pull/${{ github.event.number }}/merge runs-on: ubuntu-latest
# # Optional: Change the working directory
# workingDirectory: apps/www # pull_request_target opened event from forked repo
# wranglerVersion: '3' if: ${{
github.event_name == 'pull_request_target' &&
github.event.action == 'opened' &&
github.event.pull_request.head.repo.fork == true
}}
steps:
- name: Create PR comment
run: |
cat << EOF > comment.md
# ⚠️ \`🚀request-deploy\` label is required for deployment
This repository is a forked repository.
Due to security reasons, deployment from forked repositories does not happen automatically.
To request deployment, please add the \`🚀request-deploy\` label to this pull request.
(Only certain members have the ability to add labels.)
EOF
gh pr comment ${{ github.event.number }} -R ${{ github.repository }} -F comment.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}