diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 00000000..b61b6cbb --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,44 @@ +name: Lint + +on: + pull_request: + branches: + - master + - migrate_to_gha # for debug + paths: + - '**/*.rb' + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2 # 必要な Ruby バージョン + - name: Restore Gem cache + uses: actions/cache@v4 + with: + path: vendor/bundle + key: lint-${{ hashFiles('Gemfile.lock') }} + - name: Install dependencies + run: | + bundle config set --local path 'vendor/bundle' + bundle config set --local with 'development' + bundle install + - name: Set up upstream + run: | + git remote add upstream https://github.com/${{ github.event.pull_request.base.repo.full_name }}.git + git remote -v + git fetch upstream + git fetch --all + git branch -r + + - name: Run RuboCop + run: | + git merge-base upstream/${{ github.base_ref }} HEAD + git diff --name-only upstream/${{ github.base_ref }}...HEAD -- '*.rb' | xargs -r bundle exec rubocop -f html --out report.html + + - name: Upload RuboCop report + uses: actions/upload-artifact@v4 diff --git a/.github/workflows/system_test.yaml b/.github/workflows/system_test.yaml new file mode 100644 index 00000000..f49976d1 --- /dev/null +++ b/.github/workflows/system_test.yaml @@ -0,0 +1,57 @@ +name: System test + +on: + push: + branches: + - master + - migrate_to_gha + pull_request: + branches: + - master + - migrate_to_gha + +jobs: + generate_cache: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Restore Docker cache + uses: actions/cache@v4 + with: + path: ~/caches/images.tar + key: docker-${{ hashFiles('.github/workflows/ci.yml', 'docker-compose.system-test.yml', 'Dockerfile.system-test', 'bucky-core.gemspec', '.dockerignore') }} + - name: Build and cache Docker images + run: | + if [ ! -f ~/caches/images.tar ]; then + docker-compose -f docker-compose.system-test.yml build + mkdir -p ~/caches + docker save $(docker images | awk 'NR>=2 && ! /^/{print $1}') -o ~/caches/images.tar + fi + + run: + runs-on: ubuntu-latest + needs: generate_cache_for_system_test + strategy: + matrix: + shard: [1, 2] + steps: + - uses: actions/checkout@v4 + - name: Restore Docker cache + uses: actions/cache@v4 + with: + path: ~/caches/images.tar + key: docker-${{ hashFiles('.github/workflows/ci.yml', 'docker-compose.system-test.yml', 'Dockerfile.system-test', 'bucky-core.gemspec', '.dockerignore') }} + - name: Load Docker images + run: docker load -q -i ~/caches/images.tar + - name: Start Docker services + run: docker-compose -f docker-compose.system-test.yml up -d + - name: Run system tests + run: | + find system_testing/testing_code -name "*.bats" | xargs -n 1 -I {} docker exec bucky-core bats "/bucky-core/"{} | tee test-results-${{ matrix.shard }}.log + - name: Stop Docker services + run: docker-compose -f docker-compose.system-test.yml down + - name: Upload test logs + uses: actions/upload-artifact@v4 + with: + name: system-test-logs + path: test-results-*.log \ No newline at end of file diff --git a/.github/workflows/unit_test.yaml b/.github/workflows/unit_test.yaml new file mode 100644 index 00000000..034320de --- /dev/null +++ b/.github/workflows/unit_test.yaml @@ -0,0 +1,55 @@ +name: Unit test + +on: + push: + branches: + - master + - migrate_to_gha + pull_request: + branches: + - master + - migrate_to_gha + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2 # 必要な Ruby バージョン + - name: Restore Gem cache + uses: actions/cache@v4 + with: + path: vendor/bundle + key: unit-test-${{ hashFiles('Gemfile.lock') }} + - name: Install dependencies + run: | + bundle config set --local path 'vendor/bundle' + bundle config set --local with 'development' + bundle install + - name: Add bundle bin to PATH + run: echo "$(pwd)/vendor/bundle/bin" >> $GITHUB_PATH + - name: Run tests + run: | + bundle exec rspec --format html -o rspec-report.html + - name: Upload RSpec HTML report + uses: actions/upload-artifact@v4 + with: + name: rspec-html-report + path: rspec-report.html + - name: Check coverage threshold + env: + COVERAGE_THRESHOLD: 90 + run: | + COVERAGE=$(jq '.result.covered_percent' coverage/.last_run.json) + if [[ -z "$COVERAGE" || ! "$COVERAGE" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then + echo "Failed to extract coverage percentage." + exit 1 + fi + echo "Coverage: $COVERAGE%" + if (( $(echo "$COVERAGE < $COVERAGE_THRESHOLD" | bc -l) )); then + echo "Test coverage ($COVERAGE%) is below the threshold ($COVERAGE_THRESHOLD%)" + exit 1 + fi \ No newline at end of file