Skip to content

Add a workflow to keep meta-package versions in sync #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions .github/workflows/meta-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Meta-package

on:
workflow_call:
workflow_dispatch:
inputs:
dry-run:
required: false
type: boolean
default: true

jobs:
sync:
name: Sync
runs-on: ubuntu-latest
outputs:
tags-matrix: steps.tags-matrix.outputs.result
latest-release: steps.latest-release.outputs.result
steps:
- uses: actions/checkout@v3
with:
repository: ${{ secrets.META_PACKAGE }}

- name: Get upstream package name
id: package
run: echo "::set-output name=package-name::$(jq -r '.require | map_values(select(. == "self.version")) | keys[0]' composer.json)"

- name: Generate diff of versions arrays
id: tags-matrix
uses: actions/github-script@v6
env:
PACKAGE: ${{ steps.package.outputs.package-name }}
META: ${{ secrets.META_PACKAGE }}
with:
script: |
const { PACKAGE, META } = process.env
const currrentTags = github.rest.repos.listTags({
owner: context.repo.owner,
repo: META.substring(str.indexOf('/') + 1),
})
const upstreamTags = github.rest.repos.listTags({
owner: context.repo.owner,
repo: PACKAGE.substring(str.indexOf('/') + 1),
per_page: 15
})
return upstreamTags.filter((tag) => !currrentTags.includes(tag))

- name: Extract latest release
id: latest-release
env:
TAGS: ${{ steps.tags-matrix.outputs.result }}
run: echo "::set-output name=result::$(jq -r '.[0]' <<< "$TAGS")"

generate-token:
name: Token
runs-on: ubuntu-latest
outputs:
token: steps.generate-token.outputs.token
steps:
- name: Generate token
uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.BOT_APP_ID }}
private_key: ${{ secrets.BOT_PRIVATE_KEY }}

tags:
name: Tags
runs-on: ubuntu-latest
needs:
- sync
- generate-token
if: needs.sync.outputs.tags-matrix
strategy:
fail-fast: false
matrix:
tag: ${{ fromJSON(needs.sync.outputs.tags-matrix) }}
steps:
- uses: actions/checkout@v3
with:
repository: ${{ secrets.META_PACKAGE }}
token: ${{ needs.generate-token.outputs.token }}

- name: Create a tag
uses: rickstaa/action-create-tag@v1
if: ${{ ! inputs.dry-run }}
with:
tag: ${{ matrix.tag }}
message: ${{ matrix.tag }}

release:
name: Release
runs-on: ubuntu-latest
needs:
- sync
- generate-token
- tags
if: needs.sync.outputs.latest-release
steps:
- name: Create a release
uses: softprops/action-gh-release@v1
if: ${{ ! inputs.dry-run }}
with:
repository: ${{ secrets.META_PACKAGE }}
token: ${{ needs.generate-token.outputs.token }}
body: WordPress ${{ needs.sync.outputs.latest-release }}
tag_name: ${{ needs.sync.outputs.latest-release }}
6 changes: 6 additions & 0 deletions .github/workflows/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ jobs:
REMOTE: https://${{ github.actor }}:${{ steps.generate-token.outputs.token }}@github.com/${{ github.repository_owner }}/${{ secrets.PACKAGE_PREFIX }}${{ matrix.release-type }}.git
PACKAGE: ${{ github.repository_owner }}/${{ secrets.PACKAGE_PREFIX }}${{ matrix.release-type }}
TYPE: ${{ matrix.release-type }}

meta-package:
name: Meta-package
needs:
- packager
uses: ./.github/workflows/meta-package.yml