-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SHIMAYOSHI, Takao
committed
Mar 16, 2022
0 parents
commit 53abc77
Showing
14 changed files
with
407 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Ruby | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
name: Ruby ${{ matrix.ruby-version }} | ||
strategy: | ||
matrix: | ||
ruby-version: ['2.6', '2.7', '3.0', '3.1'] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby-version }} | ||
- name: Install dependencies | ||
run: bundle install | ||
- name: Run the default task | ||
run: bundle exec rake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
*.gem | ||
*.rbc | ||
/.config | ||
/coverage/ | ||
/InstalledFiles | ||
/pkg/ | ||
/spec/reports/ | ||
/spec/examples.txt | ||
/test/tmp/ | ||
/test/version_tmp/ | ||
/tmp/ | ||
|
||
/.yardoc | ||
/_yardoc/ | ||
/doc/ | ||
/rdoc/ | ||
|
||
/.bundle/ | ||
/vendor/bundle | ||
/lib/bundler/man/ | ||
|
||
# rspec failure tracking | ||
.rspec_status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require: | ||
- rubocop-rake | ||
|
||
AllCops: | ||
TargetRubyVersion: 2.6 | ||
NewCops: disable | ||
|
||
Layout/LineLength: | ||
Max: 80 | ||
|
||
Metrics/BlockLength: | ||
Exclude: | ||
- "**/*.rake" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in capistrano-scm-local_git_upload.gemspec | ||
gemspec | ||
|
||
gem 'rake', '~> 13.0' | ||
|
||
gem 'rubocop', '~> 1.21' | ||
gem 'rubocop-rake', require: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
capistrano-scm-local_git_upload (0.1.0) | ||
capistrano (~> 3.1) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
airbrussh (1.4.0) | ||
sshkit (>= 1.6.1, != 1.7.0) | ||
ast (2.4.2) | ||
capistrano (3.17.0) | ||
airbrussh (>= 1.0.0) | ||
i18n | ||
rake (>= 10.0.0) | ||
sshkit (>= 1.9.0) | ||
concurrent-ruby (1.1.9) | ||
i18n (1.10.0) | ||
concurrent-ruby (~> 1.0) | ||
net-scp (3.0.0) | ||
net-ssh (>= 2.6.5, < 7.0.0) | ||
net-ssh (6.1.0) | ||
parallel (1.21.0) | ||
parser (3.1.1.0) | ||
ast (~> 2.4.1) | ||
rainbow (3.1.1) | ||
rake (13.0.6) | ||
regexp_parser (2.2.1) | ||
rexml (3.2.5) | ||
rubocop (1.26.0) | ||
parallel (~> 1.10) | ||
parser (>= 3.1.0.0) | ||
rainbow (>= 2.2.2, < 4.0) | ||
regexp_parser (>= 1.8, < 3.0) | ||
rexml | ||
rubocop-ast (>= 1.16.0, < 2.0) | ||
ruby-progressbar (~> 1.7) | ||
unicode-display_width (>= 1.4.0, < 3.0) | ||
rubocop-ast (1.16.0) | ||
parser (>= 3.1.1.0) | ||
rubocop-rake (0.6.0) | ||
rubocop (~> 1.0) | ||
ruby-progressbar (1.11.0) | ||
sshkit (1.21.2) | ||
net-scp (>= 1.1.2) | ||
net-ssh (>= 2.8.0) | ||
unicode-display_width (2.1.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
capistrano-scm-local_git_upload! | ||
rake (~> 13.0) | ||
rubocop (~> 1.21) | ||
rubocop-rake | ||
|
||
BUNDLED WITH | ||
1.17.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2022 TODO: Write your name | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Capistrano::Scm::LocalGitUpload | ||
|
||
[![Gem Version](https://badge.fury.io/rb/capistrano-scm-local_git_upload.svg)](https://badge.fury.io/rb/capistrano-scm-local_git_upload) | ||
![Ruby](https://github.com/simayosi/capistrano-scm-local_git_upload/actions/workflows/test.yml/badge.svg) | ||
|
||
|
||
Capistrano SCM Plugin for local git clone and upload. | ||
|
||
This plugin firstly clones the git repository to the local host | ||
and thereafter uploads files on the local host to the remote servers. | ||
|
||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
```ruby | ||
gem 'capistrano-scm-local_git_upload' | ||
``` | ||
And execute: | ||
```bash | ||
$ bundle install | ||
``` | ||
|
||
Add to Capfile: | ||
```ruby | ||
require "capistrano/scm/local_git_upload" | ||
install_plugin Capistrano::SCM::LocalGitUpload | ||
``` | ||
|
||
## Usage | ||
|
||
The git repository is cloned | ||
to `work_path` (default: `work`) on the local host | ||
before `deploy:started`. | ||
|
||
Then, | ||
files under `upload_path` (default: `upload`) on the local host | ||
are uploaded to `release_path` on the remote servers | ||
after `deploy:new_release_path`. | ||
|
||
Therefore, you need to prepare `upload_path` using `work_path` files | ||
until `deploy:new_release_path`. | ||
|
||
This is a simple copy example from `work/public` to `upload/public`. | ||
```ruby | ||
namespace :sample_app do | ||
task :copy_to_upload do | ||
run_locally do | ||
execute :cp, '-pr', work_path.join('public'), upload_path | ||
end | ||
end | ||
before 'deploy:new_release_path', 'sample_app:copy_to_upload' | ||
end | ||
``` | ||
|
||
|
||
## License | ||
|
||
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/gem_tasks' | ||
require 'rubocop/rake_task' | ||
|
||
RuboCop::RakeTask.new | ||
|
||
task default: :rubocop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
set -vx | ||
|
||
bundle install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'lib/capistrano/scm/local_git_upload/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'capistrano-scm-local_git_upload' | ||
spec.version = Capistrano::Scm::LocalGitUpload::VERSION | ||
spec.authors = ['SHIMAYOSHI, Takao'] | ||
spec.email = ['simayosi@cc.kyushu-u.ac.jp'] | ||
|
||
spec.summary = 'Capistrano::SCM::LocalGitUpload' | ||
spec.description = | ||
'Capistrano SCM plugin for local git clone and upload.' | ||
spec.homepage = 'https://github.com/simayosi/capistrano-scm-local_git_upload' | ||
spec.license = 'MIT' | ||
spec.required_ruby_version = '>= 2.6.0' | ||
|
||
spec.metadata['homepage_uri'] = spec.homepage | ||
spec.metadata['source_code_uri'] = spec.homepage | ||
spec.metadata['documentation_uri'] = spec.homepage | ||
|
||
spec.files = Dir['lib/**/*', 'LICENSE.txt', 'README.md'] | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_dependency 'capistrano', '~> 3.1' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'capistrano/scm/plugin' | ||
require 'capistrano/scm/git' | ||
|
||
module Capistrano | ||
module DSL | ||
# DSL extension for LocalGitUpload | ||
module LocalGitUpload | ||
def work_path | ||
Pathname.new fetch(:work_path) | ||
end | ||
|
||
def upload_path | ||
Pathname.new fetch(:upload_path) | ||
end | ||
end | ||
end | ||
end | ||
extend Capistrano::DSL::LocalGitUpload # rubocop:disable Style/MixinUsage | ||
include Capistrano::DSL::LocalGitUpload # rubocop:disable Style/MixinUsage | ||
|
||
module Capistrano | ||
class SCM | ||
# Capistrano SCM plugin for local git clone followed by upload | ||
class LocalGitUpload < ::Capistrano::SCM::Plugin | ||
def initialize | ||
super | ||
@git_plugin = Capistrano::SCM::Git.new | ||
end | ||
|
||
def set_defaults | ||
@git_plugin.set_defaults | ||
set_if_empty :local_top, Dir.getwd | ||
set_if_empty :repo_path, local_path('repo') | ||
set_if_empty :work_path, local_path('work') | ||
set_if_empty :upload_path, local_path('upload') | ||
end | ||
|
||
def define_tasks | ||
eval_rakefile File.expand_path('tasks/git_local.rake', __dir__) | ||
eval_rakefile File.expand_path('tasks/upload.rake', __dir__) | ||
end | ||
|
||
def register_hooks | ||
before 'deploy:check', 'upload:check_directory' | ||
before 'deploy:started', 'git_local:create_work' | ||
after 'deploy:new_release_path', 'upload:create_release' | ||
before 'deploy:set_current_revision', 'git_local:set_current_revision' | ||
after 'deploy:finishing', 'git_local:remove_directory' | ||
after 'deploy:finishing', 'upload:remove_directory' | ||
end | ||
|
||
private | ||
|
||
def local_path(path) | ||
Pathname.new(fetch(:local_top)).join(path).to_s | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module Capistrano | ||
module Scm | ||
module LocalGitUpload | ||
VERSION = '0.1.0' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
git_plugin = @git_plugin | ||
|
||
namespace :git_local do | ||
desc 'Clone the repo to the local cache' | ||
task :clone do | ||
run_locally do | ||
execute :mkdir, '-p', repo_path | ||
if git_plugin.repo_mirror_exists? | ||
info t(:mirror_exists, at: repo_path) | ||
else | ||
with fetch(:git_environmental_variables) do | ||
git_plugin.clone_repo | ||
end | ||
end | ||
end | ||
end | ||
|
||
desc 'Update the local repo mirror to reflect the origin state' | ||
task update: :clone do | ||
run_locally do | ||
within repo_path do | ||
with fetch(:git_environmental_variables) do | ||
git_plugin.update_mirror | ||
git_plugin.verify_commit if fetch(:git_verify_commit) | ||
end | ||
end | ||
end | ||
end | ||
|
||
desc 'Copy repo to the working directory' | ||
task create_work: :update do | ||
run_locally do | ||
with fetch(:git_environmental_variables) do | ||
set :release_path, work_path | ||
within repo_path do | ||
execute :mkdir, '-p', release_path | ||
git_plugin.archive_to_release_path | ||
end | ||
end | ||
end | ||
end | ||
|
||
desc 'Determine the revision that will be deployed' | ||
task :set_current_revision do | ||
run_locally do | ||
within repo_path do | ||
with fetch(:git_environmental_variables) do | ||
set :current_revision, git_plugin.fetch_revision | ||
end | ||
end | ||
end | ||
end | ||
|
||
desc 'Remove the working directory' | ||
task :remove_directory do | ||
run_locally do | ||
execute :rm, '-rf', work_path | ||
end | ||
end | ||
end |
Oops, something went wrong.