SashimiTanpopo :sushi: :blossom:
Change files and create patches
Example
# recipe.rb
update_file ".ruby-version" do |content|
content.gsub!(/^[\d.]+$/, params[:ruby_version])
end
update_file "Dockerfile" do |content|
content.gsub!(/^FROM ruby:([\d.]+)$/, %Q{FROM ruby:#{params[:ruby_version]}})
end
@ruby_minor_version = params[:ruby_version].to_f
update_file ".rubocop.yml" do |content|
content.gsub!(/TargetRubyVersion: ([\d.]+)/, "TargetRubyVersion: #{@ruby_minor_version}")
end
update_file ".github/workflows/*.yml" do |content|
content.gsub!(/ruby-version: "(.+)"/, %Q{ruby-version: "#{params[:ruby_version]}"})
end
# Update local app files using recipe.rb
$ sashimi_tanpopo local --target-dir=/path/to/app --params=ruby_version:3.4.5 /path/to/recipe.rb
# Update local app files using recipe.rb and create Pull Request
$ sashimi_tanpopo github --target-dir=/path/to/app --params=ruby_version:3.4.5 \
--message="Upgrade to Ruby 3.4.5" --github-repository=yourname/yourrepo --pr-title="Upgrade to Ruby 3.4.5" \
--pr-source-branch=ruby_3.4.5 --pr-target-branch=main --pr-draft /path/to/recipe.rb
Installation
Use gem directly
gem install sashimi_tanpopo
Use via docker
e.g.
docker run -v /path/to/recipe_dir:/recipes:ro -v $(pwd):/work --rm ghcr.io/sue445/sashimi_tanpopo <local|github|gitlab> <arguments> /recipes/recipe.rb
c.f. github.com/sue445/sashimi_tanpopo/pkgs/container/sashimi_tanpopo
Usage
sashimi_tanpopo local
Change local files using recipe files
$ sashimi_tanpopo help local
Usage:
sashimi_tanpopo local RECIPE [RECIPE...]
Options:
-d, [--target-dir=TARGET_DIR] # Target directory. Default: current directory
-p, [--params=key:value] # Params passed to recipe file
[--dry-run], [--no-dry-run], [--skip-dry-run] # Whether to run dry run
# Default: false
[--color], [--no-color], [--skip-color] # Whether to colorize output
# Default: true
sashimi_tanpopo github
Change local files using recipe files and create Pull Request on GitHub
$ sashimi_tanpopo help github
Usage:
sashimi_tanpopo github RECIPE [RECIPE...] --pr-source-branch=pr_branch --pr-title=PR_TITLE -m, --message=COMMIT_MESSAGE
Options:
-d, [--target-dir=TARGET_DIR] # Target directory. Default: current directory
-p, [--params=key:value] # Params passed to recipe file
[--dry-run], [--no-dry-run], [--skip-dry-run] # Whether to run dry run
# Default: false
[--color], [--no-color], [--skip-color] # Whether to colorize output
# Default: true
[--git-user-name=GIT_USER_NAME] # user name for git commit. Default: username of user authenticated with token
[--git-email=GIT_EMAIL] # email for git commit. Default: <git_user_name>@users.noreply.<github_host>
-m, --message=COMMIT_MESSAGE # commit message
[--github-repository=user/repo] # GitHub repository for Pull Request. One of --github--repository or $GITHUB_REPOSITORY is required [$GITHUB_REPOSITORY]
[--github-api-url=GITHUB_API_URL] # GitHub API endpoint. One of --github-api-url or $GITHUB_API_URL is required [$GITHUB_API_URL]
# Default: https://api.github.com
[--github-token=GITHUB_TOKEN] # GitHub access token. One of --github-token or $GITHUB_TOKEN is required [$GITHUB_TOKEN]
[--github-step-summary=GITHUB_STEP_SUMMARY] # Path to GitHub step summary file [$GITHUB_STEP_SUMMARY]
--pr-title=PR_TITLE # Pull Request title
[--pr-body=PR_BODY] # Pull Request body
--pr-source-branch=pr_branch # Pull Request source branch (a.k.a. head branch)
[--pr-target-branch=main] # Pull Request target branch (a.k.a. base branch). Default: default branch of repository (e.g. main, master)
[--pr-assignees=one two three] # Pull Request assignees
[--pr-reviewers=one two three] # Pull Request reviewers
[--pr-labels=one two three] # Pull Request labels
[--pr-draft], [--no-pr-draft], [--skip-pr-draft] # Whether to create draft Pull Request
# Default: false
--github-token requires followings repository permissions
-
Contents: Read and Write
-
Pull requests: Read and Write
-
Metadata: Read-only
-
Workflows: Read and Write
-
Only if you want to change
.github/workflows/*.yml
sashimi_tanpopo gitlab
Change local files using recipe files and create Merge Request on GitLabâ„¢
GITLAB is a trademark of GitLab Inc. in the United States and other countries and regions
$ sashimi_tanpopo help gitlab
Usage:
sashimi_tanpopo gitlab RECIPE [RECIPE...] --mr-source-branch=mr_branch --mr-title=MR_TITLE -m, --message=COMMIT_MESSAGE
Options:
-d, [--target-dir=TARGET_DIR] # Target directory. Default: current directory
-p, [--params=key:value] # Params passed to recipe file
[--dry-run], [--no-dry-run], [--skip-dry-run] # Whether to run dry run
# Default: false
[--color], [--no-color], [--skip-color] # Whether to colorize output
# Default: true
[--git-user-name=GIT_USER_NAME] # user name for git commit. Default: username of user authenticated with token
[--git-email=GIT_EMAIL] # email for git commit. Default: <git_user_name>@noreply.<gitlab_host>
-m, --message=COMMIT_MESSAGE # commit message
[--gitlab-project=user/repo] # GitLab project for Merge Request. One of --gitlab-project, $GITLAB_PROJECT or $CI_PROJECT_PATH is required [$GITLAB_PROJECT, $CI_PROJECT_PATH]
[--gitlab-api-url=GITLAB_API_URL] # GitLab API endpoint. One of --gitlab-api-url, $GITLAB_API_URL or $CI_API_V4_URL is required [$GITLAB_API_URL, $CI_API_V4_URL]
# Default: https://gitlab.com/api/v4
[--gitlab-token=GITLAB_TOKEN] # GitLab access token. One of --gitlab-token or $GITLAB_TOKEN is required [$GITLAB_TOKEN]
--mr-title=MR_TITLE # Merge Request title
[--mr-body=MR_BODY] # Merge Request body
--mr-source-branch=mr_branch # Merge Request source branch
[--mr-target-branch=main] # Merge Request target branch. Default: default branch of project (e.g. main, master)
[--mr-assignees=one two three] # Merge Request assignees
[--mr-reviewers=one two three] # Merge Request reviewers
[--mr-labels=one two three] # Merge Request labels
[--mr-draft], [--no-mr-draft], [--skip-mr-draft] # Whether to create draft Merge Request
# Default: false
[--mr-auto-merge], [--no-mr-auto-merge], [--skip-mr-auto-merge] # Whether to set auto-merge to Merge Request
# Default: false
--gitlab-token requires followings permissions
-
Role: Developer
-
Scopes:
api
Recipe file specification
See docs/RECIPE.md
Use on CI services
GitHub Actions
See github.com/marketplace/actions/sashimi_tanpopo_action
GitLab CI
See gitlab.com/explore/catalog/sue445/sashimi_tanpopo-components
Real example
sashimi_tanpopo is used to manage configuration files for my multiple personal repositories.
See followings.
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at github.com/sue445/sashimi_tanpopo.
License
The gem is available as open source under the terms of the MIT License.