-
Notifications
You must be signed in to change notification settings - Fork 2
chore: Initial PR for creating pre-release tags for a plugin #273
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
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9efa56c
Initial update of the previews plugin package.json for changsets.
colinmurphy 8b3fee2
Fix changeset syntax error.
colinmurphy f2754dd
Removed ignore directories as not required.
colinmurphy 4e353d3
Added Changeset
colinmurphy 1f61f66
Fixing main package-lock.json file to get e2e tests to run.
colinmurphy 90d2934
Merge branch 'chore-setup-release-workflow-iteration-1' of github.com…
colinmurphy c427ec3
Setup of docs and starting to create release process.
colinmurphy 1b418ab
Added GH workflow for plugin releases etc. No idea until we test it w…
colinmurphy 9d59dd5
Fixed npm issue. Updated e2e test to use cached composer directory fo…
colinmurphy ebb0eeb
Added Changeset
colinmurphy 62a8db4
Delete .changeset/warm-dolphins-brake.md
colinmurphy 01401d2
Small typo fix.
colinmurphy 8fa9253
Merge branch 'chore-setup-release-workflow-iteration-1' of github.com…
colinmurphy d6322d1
Simplifying PR as we only need pre-release tags not a full release pr…
colinmurphy 3c90f66
Fixes and inlucde updating the changeset version of the plugin.
colinmurphy 9706b07
Fixes.
colinmurphy ea2411a
Reverted deleting package-lock.json as it is needed for e2e tests.
colinmurphy 69cdb6a
Updated package name. Thanks @theodesp . Updated logic of pre-release…
colinmurphy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@hwp-previews/wordpress-plugin": patch | ||
| --- | ||
|
|
||
| chore: Initial release of hwp-previews beta release. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| name: 'Create Plugin Release' | ||
| description: 'Upload zip file to releases tab' | ||
| branding: | ||
| icon: 'upload-cloud' | ||
| color: 'blue' | ||
|
|
||
| inputs: | ||
| github_token: | ||
| description: 'GitHub Token' | ||
| required: true | ||
| php: | ||
| description: 'PHP version to use' | ||
| required: true | ||
| directory: | ||
| description: 'Plugin slug (directory name under plugins/)' | ||
| required: true | ||
| composer-options: | ||
| description: 'Additional composer options' | ||
| required: false | ||
| default: '--no-progress' | ||
|
|
||
| outputs: | ||
| zip-path: | ||
| description: 'Path to zip file' | ||
| value: ${{ steps.zip-main-release-for-github.outputs.zip-path }} | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - id: prepare | ||
| name: Prepare Environment | ||
| run: sudo apt-get update && sudo apt-get install zip rsync -y | ||
| shell: bash | ||
|
|
||
| - name: Setup PHP with Cached Composer | ||
| uses: ./.github/actions/setup-php-composer | ||
| with: | ||
| php-version: ${{ inputs.php }} | ||
| working-directory: plugins/${{ inputs.slug }} | ||
| composer-options: ${{ inputs.composer-options }} | ||
|
|
||
| - id: create-asset-release-version | ||
| name: Create asset release version without quotes | ||
| run: | | ||
| ASSET_RELEASE_VERSION=$(echo ${{ env.VERSION }} | tr -d '"') | ||
| echo "ASSET_RELEASE_VERSION=$ASSET_RELEASE_VERSION" >> $GITHUB_ENV | ||
| shell: bash | ||
|
|
||
| - name: Create plugin artifact | ||
| working-directory: plugins/${{ inputs.slug }} | ||
| run: | | ||
| mkdir -p plugin-build | ||
| rm -f plugin-build/${{ inputs.slug }}-*.zip | ||
| composer archive -vvv --format=zip --file="plugin-build/${{ inputs.slug }}.${{ env.VERSION }}" --dir="." | ||
| shell: bash | ||
|
|
||
| - id: upload-main-release-to-github | ||
| name: Uploads the main release zip file to GitHub | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| token: ${{ inputs.github_token }} | ||
| files: plugins/${{ inputs.slug }}/plugin-build/${{ inputs.slug }}.${{ env.VERSION }}.zip | ||
| asset_name: ${{ inputs.slug }}.${{ env.VERSION }}.zip | ||
| tag_name: "${{ env.NAME }}@${{ env.ASSET_RELEASE_VERSION }}" | ||
| overwrite: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| name: Create Plugin Release Branch | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "plugins/**" | ||
|
|
||
| jobs: | ||
| create-release-branch: | ||
| name: Create Plugin Release Branch | ||
| runs-on: ubuntu-22.04 | ||
| steps: | ||
| - name: Checkout Repo | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup Node.js 18.x | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 18.x | ||
|
|
||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v3 | ||
| with: | ||
| version: 8 # min version for the toolkit | ||
|
|
||
| - name: Install Dependencies | ||
| run: pnpm install | ||
|
|
||
| - name: Get changed plugin directory | ||
| id: plugin | ||
| run: | | ||
| git fetch --prune --unshallow | ||
| plugin=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2) | ||
| echo "slug=$plugin" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Validate package.json | ||
| run: | | ||
| if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/package.json" ]; then | ||
| echo "Exiting as no package.json file found so we cannot generate a changeset for this plugin - /${{ steps.plugin.outputs.slug }}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Gather package name | ||
| run: | | ||
| package_name=$(jq -r '.name // empty' "plugins/${{ steps.plugin.outputs.slug }}/package.json") | ||
| if [ -z "$package_name" ]; then | ||
| echo "No package name found in plugins/${{ steps.plugin.outputs.slug }}/package.json" | ||
| exit 1 | ||
| fi | ||
| echo "PACKAGE_NAME=$package_name" >> $GITHUB_ENV | ||
|
|
||
| - name: Create Release Pull Request or Publish to npm | ||
| id: changesets | ||
| uses: changesets/action@v1 | ||
| with: | ||
| publish: pnpm release | ||
| version: pnpm version:${{ steps.plugin.outputs.slug }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| name: Release Plugin | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "plugins/**" | ||
|
|
||
| jobs: | ||
| create-github-release: | ||
| name: Create Github Release | ||
| runs-on: ubuntu-22.04 | ||
| steps: | ||
| - name: Checkout Repo | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup Node.js 18.x | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 18.x | ||
|
|
||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v3 | ||
| with: | ||
| version: 8 # min version for the toolkit | ||
|
|
||
| - name: Install Dependencies | ||
| run: pnpm install | ||
|
|
||
| - name: Get changed plugin directory | ||
| id: plugin | ||
| run: | | ||
| git fetch --prune --unshallow | ||
| plugin=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2) | ||
| echo "slug=$plugin" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Validate package.json | ||
| run: | | ||
| if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/package.json" ]; then | ||
| echo "Exiting as no package.json file found so we cannot generate a changeset for this plugin - /${{ steps.plugin.outputs.slug }}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Gather package name | ||
| run: | | ||
| package_name=$(jq -r '.name // empty' "plugins/${{ steps.plugin.outputs.slug }}/package.json") | ||
| if [ -z "$package_name" ]; then | ||
| echo "No package name found in plugins/${{ steps.plugin.outputs.slug }}/package.json" | ||
| exit 1 | ||
| fi | ||
| echo "PACKAGE_NAME=$package_name" >> $GITHUB_ENV | ||
|
|
||
| - name: Save Plugin version | ||
| run: | | ||
| json=${{ toJSON(steps.changesets.outputs.publishedPackages) }} | ||
| echo PLUGIN_VERSION=$(echo "$json" | jq --arg name "$PACKAGE_NAME" '.[] | select(.name == $name) | .version') >> $GITHUB_ENV | ||
|
|
||
| - name: Create Github Release | ||
| # Checks the changesets publishedPackages output | ||
| # If there is a published package named after the plugin slug, | ||
| # Then deploy the WordPress plugin | ||
| # https://github.com/changesets/action#outputs | ||
| if: steps.changesets.outputs.published && contains(steps.changesets.outputs.publishedPackages, format('"{0}"', steps.plugin.outputs.slug)) | ||
| uses: ./.github/actions/release-plugin | ||
| with: | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| php: 8.2 | ||
| composer-options: '--no-progress --optimize-autoloader --no-dev' | ||
| slug: ${{ steps.plugin.outputs.slug }} | ||
| env: | ||
| VERSION: ${{ env.PLUGIN_VERSION }} | ||
| NAME: ${{ env.PACKAGE_NAME }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Overview | ||
|
|
||
| This is an explanation on how a plugin is released on GitHub. | ||
|
|
||
| # Workflow | ||
|
|
||
| ## High Level project structure for release process | ||
|
|
||
| ``` | ||
| . | ||
| └── package.json # Contains scripts to update the different plugin versions | ||
| │ | ||
| └── .changeset | ||
| │ └── config.json # Changeset config file | ||
| ├── .github | ||
| │ └── workflows | ||
| │ ├── release-branch.yml # Creates the release branch | ||
| │ └── release-plugin.yml # Creates the GitHub release | ||
| ├── plugin | ||
| │ └── hwp-previews | ||
| │ └── package.json # Required for changeset to work | ||
| │ └── wp-graphql-headless-webhooks | ||
| │ └── package.json # Required for changeset to work | ||
| ├── scripts/ | ||
| │ └── plugin-version | ||
| │ ├── previewsVersionPlugin.js # Updates the version of hwp-previews plugin | ||
| │ └── webhooksVersionPlugin.js # Updates the version of wp-graphql-headless-webhooks plugin | ||
| ``` | ||
|
|
||
| ## 1. PR creation | ||
|
|
||
| 1. A create PR is created for a plugin | ||
| 2. This triggers the [changeset bot](https://github.com/changesets/bot) to check for a changeset. | ||
| 3. A user can add a changeset manually by running `npm run changeset` or if they are a maintainer, they can do this also in GitHub | ||
| 4. Once the PR is merged the following actions will take place: | ||
|
|
||
|
|
||
| ## 2. PR merged to the main branch | ||
|
|
||
| This will trigger the release workflow [release-branch.yml](../../.github/workflows/release-branch.yml) and the workflow will do the following: | ||
|
|
||
| 1. Check to see if a changeset exists | ||
| 2. Check that a plugin is modified | ||
| 3. Create a release branch for that plugin using `npm run build && changeset publish | ||
| 4. Depending on what plugin is changed it will either run `npm run version:previews` or `npm run version:webhooks` which will call a script for updating the plugin version under [scripts/plugin-version](../../scripts/plugin-version/) | ||
|
|
||
| After this a plugin release branch is created. See <https://github.com/wpengine/hwptoolkit/pulls?q=Plugin+Release> | ||
|
|
||
| >[!NOTE] | ||
| > If you are adding a new plugin, you will need to add a script and also update this workflow, along with adding a package.json while updating the main package-lock.json by running `npm install` | ||
|
|
||
|
|
||
| ## 3. Plugin Release Branch | ||
|
|
||
| The plugin release branch should contain some updates to the plugin and mainly the plugin version number. | ||
|
|
||
| Once approved and merged this will trigger the [release-plugin.yml](../../.github/workflows/release-plugin.yml) | ||
|
|
||
| This will then create a release for the plugin under [Github releases](https://github.com/wpengine/hwptoolkit/releases) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.