 
			WordPress 最近要发布 6.3 版本了,在发布前都会收到WordPress x.x is imminent! Are your plugins ready?的邮件来提醒我更新插件兼容。
以下插件都没及时更新 readme.txt 来表示兼容新版本,主要是觉得挨个更新费时费力。
- https://wordpress.org/plugins/baidu-textcensor/ (tested up to 5.8.7)
- https://wordpress.org/plugins/imagex/ (tested up to 5.6.11)
- https://wordpress.org/plugins/kodo-qiniu/ (tested up to 5.9.7)
- https://wordpress.org/plugins/memorialday/ (tested up to 6.2.2)
- https://wordpress.org/plugins/obs-huaweicloud/ (tested up to 5.6.11)
- https://wordpress.org/plugins/oss-aliyun/ (tested up to 6.2.2)
- https://wordpress.org/plugins/push-message-to-wechat/ (tested up to 5.3.15)
- https://wordpress.org/plugins/random-look/ (tested up to 5.4.13)
- https://wordpress.org/plugins/realtimehot-weibo/ (tested up to 5.3.15)
- https://wordpress.org/plugins/sync-qcloud-cos/ (tested up to 5.9.7)
- https://wordpress.org/plugins/textcensor-for-articles/ (tested up to 5.6.11)
- https://wordpress.org/plugins/uss-upyun/ (tested up to 6.2.2)
前几天发现有一个 action(10up/action-wordpress-plugin-deploy) 支持在 GitHub 上直接推送到 WordPress Plugin SVN 中。
所以就写了一个 deploy.yml的工作流:
name: Deploy to WordPress.org
on:
  pull_request:
  release:
    types: [ published ]
jobs:
  tag:
    name: New release
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '7.0'
        tools: composer
    - name: Build
      run: |
        composer install -o --no-dev
      working-directory: cos-sdk-v5
    - name: Set Version
      if: github.event_name == 'pull_request'
      run: |
        echo "VERSION=ci" >> $GITHUB_ENV
    - name: WordPress Plugin Deploy
      id: deploy
      uses: 10up/action-wordpress-plugin-deploy@stable
      with:
        dry-run: ${{ github.event_name == 'pull_request' }}
        generate-zip: ${{ github.event_name == 'release' }}
      env:
        SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
        SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
        SLUG: sync-qcloud-cos
    - name: Upload release asset
      uses: actions/upload-release-asset@v1
      if: github.event_name == 'release'
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ github.event.release.upload_url }}
        asset_path: ${{ steps.deploy.outputs.zip-path }}
        asset_name: ${{ github.event.repository.name }}.zip
        asset_content_type: application/zip嗯,不错,可以用。但是后来发现问题不是这么简单,现在有 10+插件,挨个复制提交的话,现在是没问题,但是后面如果要修改yml中的内容的话,又得重新挨个修改,依旧是一个重复性的工作。
至此,引出本文要讲述的内容:怎么复用 Workflows?
为什么需要复用?
可以使工作流程可重复使用,而不是从一个工作流程复制并粘贴到另一个工作流程。 自己和有权访问可重用工作流程的任何人都可以从另一个工作流程调用可重用工作流程。
重用工作流程可避免重复。 这使得工作流程更易于维护。
组织也可以构建可集中维护的可重用工作流程库。
创建可重用的工作流程
若要使工作流可重用,on 的值必须包括 workflow_call:
on:
  workflow_call:同时可以定义输入和机密,这些输入和机密可以从调用方工作流程传递,然后在被调用的工作流程中使用。
on:
  workflow_call:
    inputs:
      build:
        default: false
        type: boolean
      php:
        default: "7.0"
        type: string
      working-directory:
        default: sdk
        type: string如果在调用工作流中使用 secrets: inherit 继承机密,那么即使未在 on 键中显式定义机密,也可以引用它们。
其他的就和普通的工作流程定义一致了。
修改完成后的文件
name: WordPress Plugin Deploy
on:
  workflow_call:
    inputs:
      build:
        default: false
        type: boolean
      php:
        default: "7.0"
        type: string
      working-directory:
        default: sdk
        type: string
jobs:
  deploy:
    name: Deploy to WordPress.org
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Setup PHP
        if: ${{ inputs.build }}
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ inputs.php }}
          tools: composer
      - name: Install dependencies
        if: ${{ inputs.build }}
        run:
          composer install -o --no-dev
        working-directory: ${{ inputs.working-directory }}
      - name: Set Version
        if: github.event_name == 'pull_request'
        run: |
          echo "VERSION=ci" >> $GITHUB_ENV
      - name: WordPress Plugin Deploy
        id: deploy
        uses: 10up/action-wordpress-plugin-deploy@stable
        with:
          dry-run: ${{ github.event_name == 'pull_request' }}
          generate-zip: ${{ github.event_name == 'release' }}
        env:
          SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
          SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
          SLUG: ${{ secrets.PLUGIN_SLUG }}
      - name: Upload release asset
        uses: actions/upload-release-asset@v1
        if: github.event_name == 'release'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: ${{ steps.deploy.outputs.zip-path }}
          asset_name: ${{ github.event.repository.name }}.zip
          asset_content_type: application/zip调用
通过uses语法就可以调用可重用工作流。
可以直接在jobs中调用可重用工作流程,而不是从steps中。
可以使用以下语法之一引用可重用的工作流文件:
- {owner}/{repo}/.github/workflows/{filename}@{ref}用于公共和专用存储库中的可重用工作流。
- ./.github/workflows/{filename}用于同一存储库中的可重用工作流。
在第一个选项中,{ref} 可以是 SHA、发布标记或分支名称。
name: Deploy to WordPress.org
on:
  pull_request:
  release:
    types: [ published ]
jobs:
  deploy:
    uses: sy-records/.github/.github/workflows/wordpress-plugin-deploy.yaml@main
    with:
      build: true
    secrets: inherit这样就完成了可复用的工作流程定义。
本文示例中的调用方:https://github.com/sy-records/upyun-uss-wordpress/blob/master/.github/workflows/deploy.yml
本文实例中的被调用方:https://github.com/sy-records/.github/blob/main/.github/workflows/wordpress-plugin-deploy.yaml
完整的内容可以查看 GitHub 文档:Reusing workflows
 任何个人或团体,未经允许禁止转载本文:
任何个人或团体,未经允许禁止转载本文:

 
					 
					 
					 
							 
							 
							
发表评论
沙发空缺中,还不快抢~