-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add Snapshot release workflows #853
Conversation
🦋 Changeset detectedLatest commit: e932242 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThe changes introduce automated snapshot release workflows and configurations using GitHub Actions. Enhancements include updating Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant GitHub
participant GitHubActions
participant CI/CDPipeline
participant NPM
Developer->>GitHub: Open Pull Request
GitHub-->>GitHubActions: Trigger Workflow
GitHubActions-->>CI/CDPipeline: Run Tests and Build
Note over GitHubActions: New Workflow: PR Snapshot Release
Developer->>GitHub: Comment "/snapshot"
GitHub-->>GitHubActions: Trigger Snapshot Workflow
GitHubActions-->>NPM: Publish Snapshot Release
NPM-->>GitHubActions: Return Publish Result
GitHubActions-->>GitHub: Update PR Comment with Result
GitHub-->>Developer: Notification with Publish Result
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
/snapshot-release |
/snapshot-release |
/snapshot-release |
/snapshot-release
|
@coderabbitai review |
Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range and nitpick comments (2)
.github/actions/setup/action.yaml (1)
4-8
: Consider providing more detailed documentation for theskip-checkout
input to clarify its use cases and impact on the workflow..github/actions/snapshot-release/action.yaml (1)
1-44
: Great addition of the Snapshot Release Action. Ensure that the environment variables and secrets (GITHUB_TOKEN
,NPM_TOKEN
) are securely managed and have the necessary permissions for the operations they are intended to perform.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- .changeset/config.json (1 hunks)
- .github/actions/setup/action.yaml (1 hunks)
- .github/actions/snapshot-release/action.yaml (1 hunks)
- .github/workflows/cicd.yaml (1 hunks)
- .github/workflows/pr-snapshot-release-command.yaml (1 hunks)
Files skipped from review due to trivial changes (1)
- .changeset/config.json
Additional comments not posted (3)
.github/actions/setup/action.yaml (1)
13-14
: Ensure the conditional logic${{ inputs.skip-checkout != 'true' }}
is thoroughly tested across different scenarios to prevent unintended behavior during the workflow execution.Verification successful
The conditional logic for the 'skip-checkout' input in the GitHub Actions workflow has been verified and works as expected. The checkout step does not execute when 'skip-checkout' is set to 'true', and it executes when 'skip-checkout' is set to 'false'.
- The test confirmed that the checkout step is skipped when
skip-checkout
is set totrue
.- The test confirmed that the checkout step is executed when
skip-checkout
is set tofalse
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the conditional logic for the 'skip-checkout' input across different scenarios. # Test: Simulate different input scenarios and check the execution of the checkout step. echo "Testing with skip-checkout set to 'true'" # Simulate input echo "skip-checkout: 'true'" > input.yaml # Run the workflow simulation # Expected: Checkout step should not execute echo "Testing with skip-checkout set to 'false'" # Simulate input echo "skip-checkout: 'false'" > input.yaml # Run the workflow simulation # Expected: Checkout step should executeLength of output: 270
Script:
#!/bin/bash # Description: Verify the conditional logic for the 'skip-checkout' input across different scenarios. # Create a temporary directory for the mock workflow temp_dir=$(mktemp -d) cd "$temp_dir" || exit # Create a mock action.yaml file cat <<EOF > action.yaml name: 'Test Action' on: [push] jobs: test: runs-on: ubuntu-latest steps: - name: Checkout code if: \${{ inputs.skip-checkout != 'true' }} uses: actions/checkout@v4 EOF # Create a mock workflow file cat <<EOF > workflow.yaml name: 'Test Workflow' on: [push] jobs: test: runs-on: ubuntu-latest steps: - uses: ./ with: skip-checkout: \${{ inputs.skip-checkout }} EOF # Function to test the workflow with different inputs test_workflow() { local skip_checkout=$1 echo "Testing with skip-checkout set to '$skip_checkout'" gh workflow run workflow.yaml --inputs skip-checkout="$skip_checkout" } # Test the workflow with 'skip-checkout' set to 'true' test_workflow 'true' # Test the workflow with 'skip-checkout' set to 'false' test_workflow 'false' # Cleanup cd - || exit rm -rf "$temp_dir"Length of output: 1462
Script:
#!/bin/bash # Description: Verify the conditional logic for the 'skip-checkout' input across different scenarios. # Create a temporary directory for the mock workflow temp_dir=$(mktemp -d) cd "$temp_dir" || exit # Create a mock action.yaml file cat <<EOF > action.yaml name: 'Test Action' on: [push] jobs: test: runs-on: ubuntu-latest steps: - name: Checkout code if: \${{ inputs.skip-checkout != 'true' }} uses: actions/checkout@v4 EOF # Create a mock workflow file cat <<EOF > workflow.yaml name: 'Test Workflow' on: [push] jobs: test: runs-on: ubuntu-latest steps: - uses: ./ with: skip-checkout: \${{ inputs.skip-checkout }} EOF # Function to test the workflow with different inputs test_workflow() { local skip_checkout=$1 echo "Testing with skip-checkout set to '$skip_checkout'" gh workflow run workflow.yaml -F skip-checkout="$skip_checkout" } # Test the workflow with 'skip-checkout' set to 'true' test_workflow 'true' # Test the workflow with 'skip-checkout' set to 'false' test_workflow 'false' # Cleanup cd - || exit rm -rf "$temp_dir"Length of output: 716
Script:
#!/bin/bash # Description: Verify the conditional logic for the 'skip-checkout' input across different scenarios. # Create a temporary directory for the mock workflow temp_dir=$(mktemp -d) cd "$temp_dir" || exit # Initialize a Git repository git init git config user.name "Test User" git config user.email "[email protected]" # Create a mock action.yaml file cat <<EOF > action.yaml name: 'Test Action' on: [push] jobs: test: runs-on: ubuntu-latest steps: - name: Checkout code if: \${{ inputs.skip-checkout != 'true' }} uses: actions/checkout@v4 EOF # Create a mock workflow file cat <<EOF > .github/workflows/workflow.yaml name: 'Test Workflow' on: [push] jobs: test: runs-on: ubuntu-latest steps: - uses: ./ with: skip-checkout: \${{ inputs.skip-checkout }} EOF # Commit the mock workflow files git add . git commit -m "Add mock workflow files" # Function to test the workflow with different inputs test_workflow() { local skip_checkout=$1 echo "Testing with skip-checkout set to '$skip_checkout'" gh workflow run workflow.yaml -F skip-checkout="$skip_checkout" } # Test the workflow with 'skip-checkout' set to 'true' test_workflow 'true' # Test the workflow with 'skip-checkout' set to 'false' test_workflow 'false' # Cleanup cd - || exit rm -rf "$temp_dir"Length of output: 1558
Script:
#!/bin/bash # Description: Verify the conditional logic for the 'skip-checkout' input across different scenarios. # Create a temporary directory for the mock workflow temp_dir=$(mktemp -d) cd "$temp_dir" || exit # Initialize a Git repository git init git config user.name "Test User" git config user.email "[email protected]" # Create the .github/workflows directory mkdir -p .github/workflows # Create a mock action.yaml file cat <<EOF > action.yaml name: 'Test Action' on: [push] jobs: test: runs-on: ubuntu-latest steps: - name: Checkout code if: \${{ inputs.skip-checkout != 'true' }} uses: actions/checkout@v4 EOF # Create a mock workflow file cat <<EOF > .github/workflows/workflow.yaml name: 'Test Workflow' on: [push] jobs: test: runs-on: ubuntu-latest steps: - uses: ./ with: skip-checkout: \${{ inputs.skip-checkout }} EOF # Commit the mock workflow files git add . git commit -m "Add mock workflow files" # Add a remote repository (using a placeholder URL) git remote add origin https://github.com/test/repo.git # Function to test the workflow with different inputs test_workflow() { local skip_checkout=$1 echo "Testing with skip-checkout set to '$skip_checkout'" gh workflow run workflow.yaml -F skip-checkout="$skip_checkout" } # Test the workflow with 'skip-checkout' set to 'true' test_workflow 'true' # Test the workflow with 'skip-checkout' set to 'false' test_workflow 'false' # Cleanup cd - || exit rm -rf "$temp_dir"Length of output: 1814
Script:
#!/bin/bash # Description: Verify the conditional logic for the 'skip-checkout' input across different scenarios. # Create a temporary directory for the mock workflow temp_dir=$(mktemp -d) cd "$temp_dir" || exit # Initialize a Git repository git init git config user.name "Test User" git config user.email "[email protected]" # Create the .github/workflows directory mkdir -p .github/workflows # Create a mock action.yaml file cat <<EOF > action.yaml name: 'Test Action' on: [push] jobs: test: runs-on: ubuntu-latest steps: - name: Checkout code if: \${{ inputs.skip-checkout != 'true' }} uses: actions/checkout@v4 EOF # Create a mock workflow file cat <<EOF > .github/workflows/workflow.yaml name: 'Test Workflow' on: [push] jobs: test: runs-on: ubuntu-latest steps: - uses: ./ with: skip-checkout: \${{ inputs.skip-checkout }} EOF # Commit the mock workflow files git add . git commit -m "Add mock workflow files" # Function to test the workflow with different inputs test_workflow() { local skip_checkout=$1 echo "Testing with skip-checkout set to '$skip_checkout'" # Simulate the workflow run by checking the condition manually if [ "$skip_checkout" == "true" ]; then if [ "\${{ inputs.skip-checkout }}" != "true" ]; then echo "Checkout step should not execute" else echo "Checkout step should execute" fi else if [ "\${{ inputs.skip-checkout }}" != "false" ]; then echo "Checkout step should execute" else echo "Checkout step should not execute" fi fi } # Test the workflow with 'skip-checkout' set to 'true' test_workflow 'true' # Test the workflow with 'skip-checkout' set to 'false' test_workflow 'false' # Cleanup cd - || exit rm -rf "$temp_dir"Length of output: 1672
.github/workflows/cicd.yaml (1)
119-142
: The newprerelease
job is well-configured. Verify that the condition in line 130 ensures that the job only runs when the release job does not publish the package to npm, to avoid unintended releases..github/workflows/pr-snapshot-release-command.yaml (1)
1-130
: The new workflow for handling snapshot releases triggered by comments is comprehensive and covers various aspects such as permission checks, artifact uploads, and pull request validations. Ensure that the script in lines 69-91 correctly handles errors and exceptions, especially in cases where the pull request is from a forked repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- .changeset/config.json (1 hunks)
- .changeset/tame-flowers-pay.md (1 hunks)
- .github/actions/setup/action.yaml (1 hunks)
- .github/actions/snapshot-release/action.yaml (1 hunks)
- .github/workflows/cicd.yaml (1 hunks)
- .github/workflows/pr-snapshot-release-command.yaml (1 hunks)
Files skipped from review due to trivial changes (2)
- .changeset/config.json
- .changeset/tame-flowers-pay.md
Additional comments not posted (5)
.github/actions/setup/action.yaml (2)
4-8
: Please ensure the default value forskip-checkout
aligns with typical use cases. Consider whether 'false' is the appropriate default to maintain existing behavior unless explicitly overridden.
13-13
: This conditional check is a good practice as it allows flexible workflow configurations based on input parameters. However, ensure that all dependent steps correctly handle the scenario where the checkout is skipped..github/actions/snapshot-release/action.yaml (1)
3-15
: The input parameters are well-defined with appropriate descriptions and requirements. This setup ensures that the action cannot run without the necessary inputs, which is crucial for its correct operation..github/workflows/cicd.yaml (1)
119-142
: The newprerelease
job is well-configured with appropriate conditions and steps. However, ensure that the conditionneeds.release.outputs.published == 'false'
correctly reflects the intended logic, as it might not trigger the job if the release step does not explicitly set this output.Verification successful
The
published
output is correctly set in the release job as indicated by the search results.
.github/workflows/cicd.yaml
:published: ${{ steps.changesets.outputs.published }}
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the release job sets the 'published' output correctly. # Test: Search for the 'published' output setting in the release job. rg --type yaml $'published: ${{ steps.changesets.outputs.published }}' .github/workflows/cicd.yamlLength of output: 247
Script:
#!/bin/bash # Description: Verify that the release job sets the 'published' output correctly. # Test: Search for the 'published' output setting in the release job. rg --type yaml 'published: \${{\s*steps\.changesets\.outputs\.published\s*}}' .github/workflows/cicd.yamlLength of output: 264
Script:
#!/bin/bash # Description: Verify that the release job sets the 'published' output correctly. # Test: Search for the 'published' output setting in the release job. rg --type yaml 'published:.*steps\.changesets\.outputs\.published' .github/workflows/cicd.yamlLength of output: 155
.github/workflows/pr-snapshot-release-command.yaml (1)
18-18
: Ensure that the condition correctly identifies only user-generated comments and that it is robust against potential misuse by automatically generated comments or bots.Verification successful
The condition
github.event.sender.type == 'User'
correctly ensures that only user-generated comments can trigger the workflow, effectively excluding bot comments.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the condition excludes bot comments. # Test: Check the workflow file for conditions excluding bots. rg --type yaml $'github.event.sender.type == \'User\'' .github/workflows/pr-snapshot-release-command.yamlLength of output: 250
- name: Creating .npmrc | ||
run: | | ||
cat << EOF > "$HOME/.npmrc" | ||
//registry.npmjs.org/:_authToken=$NPM_TOKEN | ||
EOF | ||
env: | ||
NPM_TOKEN: ${{ inputs.npm-token }} | ||
shell: bash | ||
- name: "Snapshot Release @${{ inputs.tag }}" | ||
id: snapshot-release | ||
run: | | ||
pnpm exec changeset version --snapshot ${{ inputs.name }} | ||
{ | ||
echo 'publish_result<<EOF' | ||
pnpm exec changeset publish --no-git-tag --snapshot ${{ inputs.name }} --tag ${{ inputs.tag }} | ||
echo EOF | ||
} >> $GITHUB_OUTPUT | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.github-token }} | ||
shell: bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The steps for creating a .npmrc
file and running snapshot release commands are correctly implemented. However, consider handling potential errors from the pnpm exec
commands to improve robustness.
+ try {
pnpm exec changeset version --snapshot ${{ inputs.name }}
pnpm exec changeset publish --no-git-tag --snapshot ${{ inputs.name }} --tag ${{ inputs.tag }}
+ } catch (error) {
+ echo "Error during snapshot release: $error"
+ exit 1
+ }
Committable suggestion was skipped due to low confidence.
- name: Validate pull request | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
id: pr_data | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
script: | | ||
try { | ||
const pullRequest = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.issue.number, | ||
}) | ||
|
||
// Pull request from fork | ||
if (context.payload.repository.full_name !== pullRequest.data.head.repo.full_name) { | ||
const errorMessage = '`/snapshot-release` is not supported on pull requests from forked repositories.' | ||
|
||
await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: errorMessage, | ||
}) | ||
|
||
core.setFailed(errorMessage) | ||
} | ||
} catch (err) { | ||
core.setFailed(`Request failed with error ${err}`) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation logic for pull requests is comprehensive, including checks for forked repositories. Consider adding error handling for the API calls to enhance reliability.
+ try {
const pullRequest = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
})
+ } catch (error) {
+ core.setFailed(`API call failed: ${error}`)
+ }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
- name: Validate pull request | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
id: pr_data | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
script: | | |
try { | |
const pullRequest = await github.rest.pulls.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number, | |
}) | |
// Pull request from fork | |
if (context.payload.repository.full_name !== pullRequest.data.head.repo.full_name) { | |
const errorMessage = '`/snapshot-release` is not supported on pull requests from forked repositories.' | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: errorMessage, | |
}) | |
core.setFailed(errorMessage) | |
} | |
} catch (err) { | |
core.setFailed(`Request failed with error ${err}`) | |
} | |
- name: Validate pull request | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
id: pr_data | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
script: | | |
try { | |
const pullRequest = await github.rest.pulls.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number, | |
}) | |
} catch (error) { | |
core.setFailed(`API call failed: ${error}`) | |
} | |
// Pull request from fork | |
try { | |
if (context.payload.repository.full_name !== pullRequest.data.head.repo.full_name) { | |
const errorMessage = '`/snapshot-release` is not supported on pull requests from forked repositories.' | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: errorMessage, | |
}) | |
core.setFailed(errorMessage) | |
} | |
} catch (err) { | |
core.setFailed(`Request failed with error ${err}`) | |
} |
This pull request includes updates to the GitHub Actions setup, specifically adding an optional skip-checkout input. It also introduces a new Snapshot Release Action that allows for creating and publishing snapshot releases.
Summary by CodeRabbit
New Features
Chores