aspirepress / AspireUpdate

A plugin that allows for rewriting the URLs used to fetch updates from WordPress.org to some other endpoint
GNU General Public License v2.0
25 stars 19 forks source link

Change blueprint to based on the branch name dynamically #141

Closed ipajen closed 1 day ago

ipajen commented 1 week ago

Change blueprint to based on the branch name dynamically. Probably a GitHub action would do this on a merge for all bransch and release tags

The current blueprint for the playground is hardcoded to retrieve the AU plugin from the playground-ready branch. Change so it point to itself.

https://github.com/aspirepress/AspireUpdate/blob/main/assets/playground/blueprint.json

This change would allow for easier testing of older releases in relation to specific issues across all branches on playground.

https://aspirepress.slack.com/archives/C07Q88M2KQF/p1730827139397469

asirota commented 6 days ago

How would one dynamically alter the blueprint based on the branch name?

namithj commented 6 days ago

Only way I see is to do a search and replace via regex in actions (unless there is some branch shortcodes in GIT). Its way way easier to update blueprint once when a new branch is created though.

namithj commented 6 days ago

Should we change this to won't fix or attempt search and replace in git action or is there another solution?

ipajen commented 6 days ago

Could it work with this AI suggestion?

To make the blueprint.json dynamically fetch the appropriate branch or release tag, you can use a GitHub Action to automate the update of branch in the URL depending on the branch or tag being merged. This can be achieved by setting up a workflow that detects the branch or tag and replaces "playground-ready" in the blueprint with the correct branch or tag name.

Here’s how you can do it:

  1. Create a GitHub Action Workflow File in .github/workflows/update-blueprint.yml to run on any push to relevant branches or tags.
  2. Detect the Branch or Tag and modify the blueprint.json file accordingly. The script will read the current branch or tag and then replace "playground-ready" with that branch or tag.

Here’s an example workflow for this:

name: Update Blueprint Branch

on: push: branches:

jobs: update-blueprint: runs-on: ubuntu-latest

steps:
  - name: Checkout code
    uses: actions/checkout@v3

  - name: Set Branch or Tag Name
    id: branch-name
    run: |
      # Get the branch name or tag name and store it in an environment variable
      if [ "${{ github.ref_type }}" == "branch" ]; then
        echo "name=${{ github.ref_name }}" >> $GITHUB_ENV
      elif [ "${{ github.ref_type }}" == "tag" ]; then
        echo "name=${{ github.ref_name }}" >> $GITHUB_ENV
      fi

  - name: Update Blueprint JSON
    run: |
      # Use `jq` to edit JSON in place (ensure jq is installed in your runner)
      jq '.plugins[0] |= "https://github-proxy.com/proxy/?repo=AspirePress/AspireUpdate&branch=${name}"' assets/playground/blueprint.json > assets/playground/blueprint.json.tmp
      mv assets/playground/blueprint.json.tmp assets/playground/blueprint.json

  - name: Commit and Push Changes
    run: |
      git config --global user.name "github-actions[bot]"
      git config --global user.email "github-actions[bot]@users.noreply.github.com"
      git add assets/playground/blueprint.json
      git commit -m "Update blueprint.json for branch/tag ${{ env.name }}"
      git push
    env:
      name: ${{ env.name }}

Explanation:

•   Step 1: Checkout code – This step checks out the repository.
•   Step 2: Set Branch or Tag Name – This identifies whether the push was on a branch or tag and stores that name in the environment variable name.
•   Step 3: Update Blueprint JSON – This uses the jq command to modify blueprint.json, replacing "playground-ready" with the detected branch or tag name. jq allows us to modify JSON files from the command line.
•   Step 4: Commit and Push Changes – This commits the updated blueprint.json back to the repository.

This setup will automatically update blueprint.json to point to the appropriate branch or tag on any push to the specified branches or tags, making it more adaptable and reducing the need for manual updates.

asirota commented 5 days ago

Looks totally feasible, don't you love AI? Want to create a PR around it?

ipajen commented 5 days ago

Looks totally feasible, don't you love AI? Want to create a PR around it?

I pass, I better stick to testing ;)

costdev commented 5 days ago

The AI-generated workflow was close!

I just needed to:

costdev commented 3 days ago

@asirota Can this issue be reopened? A PR to fix the bug on this is already attached.

asirota commented 3 days ago

Done

costdev commented 3 days ago

Thanks @asirota! The PR is ready for review whenever you have time.

costdev commented 2 days ago

@asirota So while the last problem has been fixed, the next one arose: main is a protected branch, so can only be changed by merging a PR into it.

I propose that we:

That way, main just works, and when we merge to playground-ready, since it's not protected, the workflow will run and update its blueprint from main to playground-ready Sound good?

asirota commented 2 days ago

Sounds fine. Do you know where to make the change in blueprint.json. It's pretty obvious but let me know if you want me to do that.

costdev commented 2 days ago

Thanks! Yeah I know where to make the change 👍