kimseungbin / tag-and-release

A GitHub repository demonstrating automated releases using semantic versioning and a custom JavaScript GitHub Action. This project automates the tagging and release process, ensuring consistent version control and streamlined workflows.
BSD Zero Clause License
0 stars 0 forks source link

Enhance Label Checker with External Configuration and Workflow Improvements #12

Closed kimseungbin closed 11 hours ago

kimseungbin commented 17 hours ago

Summary by CodeRabbit

Close #7

coderabbitai[bot] commented 17 hours ago

Walkthrough

The changes in this pull request modify the action.yaml file for the "Release Automation Action" GitHub Action. A new required input parameter, github-token, has been added for authentication purposes, while the previously existing input parameter, name, has been removed. The execution environment and entry point specified in the runs section remain unchanged. Additionally, a new GitHub Actions workflow file named tag-and-release.yaml has been introduced, which triggers on issue and pull request events to automate tagging and releasing processes. The README.md has been updated for clarity, and a new vite.config.ts file has been added for build configurations.

Changes

File Change Summary
action.yaml - Added required input parameter github-token for authentication.
- Removed input parameter name.
- Updated author name to SeungBin Kim.
.github/workflows/tag-and-release.yaml - Introduced new workflow for automated tagging and releasing based on issue and PR events.
README.md - Added "Tools used" section mentioning Vite and Vitest.
- Restructured "Label Checker" section for clarity.
package.json - Added new script "package": "vite build" and new development dependency "vite": "^5.4.11".
src/main.ts - Updated run function to be asynchronous, changing return type to Promise<void>.
vite.config.ts - Added new configuration file for Vite build settings.
.coderabbit.yaml - Added new key poem: false and reformatted path filter.
src/main.spec.ts - Updated tests to reflect changes in input handling and error management.

Assessment against linked issues

Objective Addressed Explanation
Enhance Label Checker to fully meet objectives (Issue #7) โŒ The changes do not address the Label Checker enhancements required.

Possibly related issues

Possibly related PRs

Poem

In the land of code where rabbits play,
A new token shines bright, leading the way.
The name has hopped off, but fear not,
For with github-token, new magic is wrought!
Let's celebrate changes, both big and small,
In our GitHub garden, we cherish them all! ๐Ÿ‡โœจ


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

โค๏ธ Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
๐Ÿชง Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
kimseungbin commented 17 hours ago

Actionable comments posted: 3

๐Ÿงน Outside diff range and nitpick comments (1)

.github/workflows/tag-and-release.yaml (1)> 1-8: Consider additional architectural improvements

Based on the PR objectives, consider these enhancements:

  1. Add a configuration file (e.g., .github/label-config.yml) to externalize label definitions
  2. Add error handling and status reporting
  3. Consider adding a job to sync label configurations across repositories if needed

Would you like assistance in implementing any of these improvements?

๐Ÿงฐ Tools

๐Ÿช› actionlint 6-6: "steps" section is missing in job "label-check" (syntax-check)

8-8: "steps" section must be sequence node but got scalar node with "!!str" tag (syntax-check)

๐Ÿช› yamllint [error] 8-8: no new line character at the end of file (new-line-at-end-of-file)

๐Ÿ“œ Review details

@coderabbitai Help me with those enhancements.

coderabbitai[bot] commented 17 hours ago

[!TIP] For best results, initiate chat on the files or code changes.

@kimseungbin, I'd be happy to help you with these enhancements. Here are the steps to implement them:


1. Add a configuration file to externalize label definitions

Create a file named .github/label-config.yml in your repository to define your labels. This allows you to manage labels without hardcoding them in your action code.

labels:
  - name: bug
    color: "d73a4a"
    description: "Something isn't working"
  - name: enhancement
    color: "a2eeef"
    description: "New feature or request"
  - name: documentation
    color: "0075ca"
    description: "Improvements or additions to documentation"
  # Add more labels as needed

2. Modify your GitHub Action to read from the configuration file

Update your action code to read the labels from the configuration file and create or update them accordingly. Here's an example in JavaScript:

const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs');
const yaml = require('js-yaml');

async function run() {
  try {
    const token = core.getInput('github-token');
    const octokit = github.getOctokit(token);
    const { owner, repo } = github.context.repo;

    // Read label configuration
    const configPath = '.github/label-config.yml';
    const configFile = fs.readFileSync(configPath, 'utf8');
    const config = yaml.load(configFile);

    // Iterate over labels and create or update them
    for (const label of config.labels) {
      try {
        // Try to create the label
        await octokit.rest.issues.createLabel({
          owner,
          repo,
          name: label.name,
          color: label.color,
          description: label.description,
        });
        core.info(`Label '${label.name}' created.`);
      } catch (error) {
        if (error.status === 422) {
          // Label already exists, update it
          await octokit.rest.issues.updateLabel({
            owner,
            repo,
            name: label.name,
            new_name: label.name,
            color: label.color,
            description: label.description,
          });
          core.info(`Label '${label.name}' updated.`);
        } else {
          throw error;
        }
      }
    }

    core.info('All labels have been processed.');
  } catch (error) {
    core.setFailed(`Action failed with error: ${error.message}`);
  }
}

run();

3. Add error handling and status reporting

In the code above, error handling is implemented using try...catch blocks. If an attempt to create a label fails because it already exists (HTTP status code 422), the code updates the existing label. Any other errors cause the action to fail, and a descriptive error message is provided using core.setFailed.

4. Fix the syntax errors in your workflow file

The actionlint errors indicate issues with the steps section in your workflow file .github/workflows/tag-and-release.yaml. Here's a corrected version:

name: Tag and Release

on:
  issues:
    types: [opened, edited]
  pull_request:
    types: [opened, edited]

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

      - name: Run Label Checker
        uses: kimseungbin/tag-and-release@v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

Explanation:

5. Ensure your YAML files end with a newline

The yamllint error indicates that there's no new line character at the end of the file. Make sure to add an empty line at the end of your YAML files to adhere to best practices.

6. Consider adding a job to sync label configurations across repositories

If you manage multiple repositories and want to sync label configurations across them, you can extend your action. Here's an example:

// Add this near the beginning of your run function
const repositories = core.getInput('repositories'); // Comma-separated list of repositories

// Parse the repositories input
const repoList = repositories.split(',').map(repo => repo.trim());

for (const repoName of repoList) {
  const [owner, repo] = repoName.split('/');
  // Use the existing label processing logic for each repository
  for (const label of config.labels) {
    try {
      await octokit.rest.issues.createLabel({
        owner,
        repo,
        name: label.name,
        color: label.color,
        description: label.description,
      });
      core.info(`Label '${label.name}' created in ${owner}/${repo}.`);
    } catch (error) {
      if (error.status === 422) {
        await octokit.rest.issues.updateLabel({
          owner,
          repo,
          name: label.name,
          new_name: label.name,
          color: label.color,
          description: label.description,
        });
        core.info(`Label '${label.name}' updated in ${owner}/${repo}.`);
      } else {
        core.warning(`Failed to process label '${label.name}' in ${owner}/${repo}: ${error.message}`);
      }
    }
  }
}

Notes:

7. Update action.yaml with new inputs

Make sure your action.yaml file includes all necessary input definitions:

name: "Release Automation Action"
author: "SeungBin Kim"
description: "An action to automate labeling and releases."
inputs:
  github-token:
    description: "GitHub token for authentication"
    required: true
  repositories:
    description: "Comma-separated list of repositories to sync labels"
    required: false
runs:
  using: "node16"
  main: "dist/index.js"

Let me know if you have any questions or need further assistance implementing these enhancements!

kimseungbin commented 13 hours ago

@coderabbitai Update PR title

coderabbitai[bot] commented 13 hours ago

[!TIP] For best results, initiate chat on the files or code changes.

@kimseungbin, to update the PR title, please click on the "Edit" button (the pencil icon) next to the current title at the top of the pull request page. Then you can modify the title as needed and save your changes.

kimseungbin commented 13 hours ago

@coderabbitai Update the PR title according to the changes.

coderabbitai[bot] commented 13 hours ago

[!TIP] For best results, initiate chat on the files or code changes.

@kimseungbin, based on the changes in this pull request, I suggest updating the title to:

"Enhance Label Checker with External Configuration and Workflow Improvements"

This title reflects the following updates:

Feel free to adjust the title if needed. Let me know if you need any further assistance!