Skip to content
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

Added Github Actions to run Plugin Modernizer Tool to be used by Plugin Repositories #681

Conversation

shinigami-777
Copy link
Contributor

@shinigami-777 shinigami-777 commented Jan 21, 2025

Towards #537.
Added a GitHub Actions workflow to be used by the plugins using the Jenkins Plugin Modernizer tool .
I have included the action.yml file in the .github/workflows/ folder although it won't be used by this repo but by the plugin repos. (Is there a more suitable location to have this? )

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@shinigami-777 shinigami-777 changed the title Added Github Actions to run Plugin Modernizer Tool for Plugin Repos Added Github Actions to run Plugin Modernizer Tool to be used by Plugin Repositories Jan 21, 2025
@jonesbusy
Copy link
Collaborator

As a consumer of an action I would expect something as easy as

  - name: Run Plugin Modernizer
    uses: plugin-modernizer/modernizer-action@v2
    env:
      MODERNIZER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  1. Why do we need maven to run a simple jar that is already distributed on GitHub releases ?
  2. Why version is harcoded to 999999-SNAPSHOT
  3. Why there is harcoded action 'dry-run' ?

This PR doesn't fix not do anything. It's simply add a workflow files but doesn't implement any action to run plugin modernizer

The goal is

  • Implement a GitHub action that consumer can use in their own workflow
  • Validate this GitHub action againts a sample plugin

I'm closing this PR because it's out of scope of the #537

@jonesbusy jonesbusy closed this Jan 21, 2025
@shinigami-777
Copy link
Contributor Author

Thanks for the clarity. I understand Maven won't be necessary. Can I give this another try?

@jonesbusy
Copy link
Collaborator

I suggest taken a look at https://github.com/jreleaser/release-action (mentionned on the issue). It's an other java CLI so implmenetation should be quiete similar. The action even has a workflow to test himself : https://github.com/jreleaser/release-action/blob/main/.github/workflows/test.yml

@gounthar
Copy link
Collaborator

  1. Set Up the GitHub Action
    GitHub Actions are defined using YAML files in the .github/workflows directory. You'll also need to create the action itself, which can be implemented as a Docker container, JavaScript/TypeScript, or a composite action.

Steps:

  • Create the Action Directory:

    • Create a directory for your action, e.g., .github/actions/modernizer-action.

    • Inside this directory, create an action.yml file to define the action's metadata and inputs/outputs.

  • Define the Action:

  • Since we already have Docker images for the modernizer tool, we can use a Docker-based action. Here's an example action.yml:

name: 'Jenkins Plugin Modernizer'
description: 'Run the Jenkins Plugin Modernizer tool to update Jenkins plugins.'
inputs:
  repo-token:
    description: 'GitHub token for authentication'
    required: true
  target-branch:
    description: 'Branch to run the modernizer on'
    required: false
    default: 'main'
runs:
  using: 'docker'
  image: 'docker://ghcr.io/jenkins-infra/plugin-modernizer-tool:latest'
  args:
    - ${{ inputs.repo-token }}
    - ${{ inputs.target-branch }}
  1. Create a Workflow File:

In .github/workflows/modernizer.yml, define a workflow that uses your action. For example:

name: 'Run Jenkins Plugin Modernizer'
on:
  pull_request:
    branches:
      - main
  workflow_dispatch:

jobs:
  modernize:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Run Jenkins Plugin Modernizer
        uses: ./.github/actions/modernizer-action
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          target-branch: ${{ github.head_ref }}
  1. Publish the Action
    If you want others to use your action, you can publish it to the GitHub Marketplace or make it reusable across repositories.
  • Reusable Action: If the action is in the same repository, other workflows in that repository can reference it using uses: ./.github/actions/modernizer-action.
  • Public Action: as we want to make it public, we can publish it to the GitHub Marketplace by adding a publish.yml file (see GitHub Docs).
  1. Test the Action
  • Test the action locally using [act](https://github.com/nektos/act) (a tool for running GitHub Actions locally) or by pushing changes to a test branch in your repository.
  • Make sure the action works as expected and handles errors gracefully.
  1. Document the Action
  • Add a README.md in the action directory to explain how to use the action, its inputs/outputs, and any prerequisites.
  • Update the main repository's README.md to mention the new GitHub Action.
  1. Integrate with Jenkins Plugin Repositories
    To make it easy for Jenkins plugin repositories to use your action, you can provide a template or example workflow file that they can copy into their .github/workflows directory.

For example, they can add this to their repository:

name: 'Run Jenkins Plugin Modernizer'
on:
  pull_request:
    branches:
      - main
  workflow_dispatch:

jobs:
  modernize:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Run Jenkins Plugin Modernizer
        uses: jenkins-infra/plugin-modernizer-tool/.github/actions/modernizer-action@main
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          target-branch: ${{ github.head_ref }}
  1. Optional: Automate Updates
    Since we already use tools like Dependabot or Updatecli, you can configure them to keep the action's dependencies (e.g., Docker image tags) up to date.

We haven't set a version on the action, but it should follow the tool version.

@shinigami-777 shinigami-777 deleted the implement-github-action branch January 22, 2025 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants