|
| 1 | +name: Meta-package |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + dry-run: |
| 8 | + required: false |
| 9 | + type: boolean |
| 10 | + default: true |
| 11 | + |
| 12 | +jobs: |
| 13 | + sync: |
| 14 | + name: Sync |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + tags-matrix: steps.tags-matrix.outputs.result |
| 18 | + latest-release: steps.latest-release.outputs.result |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v3 |
| 21 | + with: |
| 22 | + repository: ${{ secrets.META_PACKAGE }} |
| 23 | + |
| 24 | + - name: Get upstream package name |
| 25 | + id: package |
| 26 | + run: echo "::set-output name=package-name::$(jq -r '.require | map_values(select(. == "self.version")) | keys[0]' composer.json)" |
| 27 | + |
| 28 | + - name: Generate diff of versions arrays |
| 29 | + id: tags-matrix |
| 30 | + uses: actions/github-script@v6 |
| 31 | + env: |
| 32 | + PACKAGE: ${{ steps.package.outputs.package-name }} |
| 33 | + META: ${{ secrets.META_PACKAGE }} |
| 34 | + with: |
| 35 | + script: | |
| 36 | + const { PACKAGE, META } = process.env |
| 37 | + const currrentTags = github.rest.repos.listTags({ |
| 38 | + owner: context.repo.owner, |
| 39 | + repo: META.substring(str.indexOf('/') + 1), |
| 40 | + }) |
| 41 | + const upstreamTags = github.rest.repos.listTags({ |
| 42 | + owner: context.repo.owner, |
| 43 | + repo: PACKAGE.substring(str.indexOf('/') + 1), |
| 44 | + per_page: 15 |
| 45 | + }) |
| 46 | + return upstreamTags.filter((tag) => !currrentTags.includes(tag)) |
| 47 | +
|
| 48 | + - name: Extract latest release |
| 49 | + id: latest-release |
| 50 | + env: |
| 51 | + TAGS: ${{ steps.tags-matrix.outputs.result }} |
| 52 | + run: echo "::set-output name=result::$(jq -r '.[0]' <<< "$TAGS")" |
| 53 | + |
| 54 | + generate-token: |
| 55 | + name: Token |
| 56 | + runs-on: ubuntu-latest |
| 57 | + outputs: |
| 58 | + token: steps.generate-token.outputs.token |
| 59 | + steps: |
| 60 | + - name: Generate token |
| 61 | + uses: tibdex/github-app-token@v1 |
| 62 | + id: generate-token |
| 63 | + with: |
| 64 | + app_id: ${{ secrets.BOT_APP_ID }} |
| 65 | + private_key: ${{ secrets.BOT_PRIVATE_KEY }} |
| 66 | + |
| 67 | + tags: |
| 68 | + name: Tags |
| 69 | + runs-on: ubuntu-latest |
| 70 | + needs: |
| 71 | + - sync |
| 72 | + - generate-token |
| 73 | + if: needs.sync.outputs.tags-matrix |
| 74 | + strategy: |
| 75 | + fail-fast: false |
| 76 | + matrix: |
| 77 | + tag: ${{ fromJSON(needs.sync.outputs.tags-matrix) }} |
| 78 | + steps: |
| 79 | + - uses: actions/checkout@v3 |
| 80 | + with: |
| 81 | + repository: ${{ secrets.META_PACKAGE }} |
| 82 | + token: ${{ needs.generate-token.outputs.token }} |
| 83 | + |
| 84 | + - name: Create a tag |
| 85 | + uses: rickstaa/action-create-tag@v1 |
| 86 | + if: ${{ ! inputs.dry-run }} |
| 87 | + with: |
| 88 | + tag: ${{ matrix.tag }} |
| 89 | + message: ${{ matrix.tag }} |
| 90 | + |
| 91 | + release: |
| 92 | + name: Release |
| 93 | + runs-on: ubuntu-latest |
| 94 | + needs: |
| 95 | + - sync |
| 96 | + - generate-token |
| 97 | + - tags |
| 98 | + if: needs.sync.outputs.latest-release |
| 99 | + steps: |
| 100 | + - name: Create a release |
| 101 | + uses: softprops/action-gh-release@v1 |
| 102 | + if: ${{ ! inputs.dry-run }} |
| 103 | + with: |
| 104 | + repository: ${{ secrets.META_PACKAGE }} |
| 105 | + token: ${{ needs.generate-token.outputs.token }} |
| 106 | + body: WordPress ${{ needs.sync.outputs.latest-release }} |
| 107 | + tag_name: ${{ needs.sync.outputs.latest-release }} |
0 commit comments