diff --git a/.bundle/config b/.bundle/config new file mode 100644 index 0000000..04f57bd --- /dev/null +++ b/.bundle/config @@ -0,0 +1,2 @@ +--- +BUNDLE_PATH: ".bundle" diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index d34458c..b7b9f26 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -7,25 +7,32 @@ assignees: fabasoad --- -**Describe the bug** +## Describe the bug + A clear and concise description of what the bug is. -**Steps to Reproduce** +## Steps to Reproduce + 1. Run '...' 2. See error -**Expected behavior** +## Expected behavior + A clear and concise description of what you expected to happen. -**Actual behavior** +## Actual behavior + A clear and concise description of what is happening now. -**Screenshots** +## Screenshots + If applicable, add screenshots to help explain your problem. -**Technical information (please complete the following information):** - - OS: [e.g. Windows 10 Enterprise v.1909 (OS Build 18363.720)] - - `linguist-action` version [e.g. 1.0.1] +## Technical information (please complete the following information) + +- OS: [e.g. Windows 10 Enterprise v.1909 (OS Build 18363.720)] +- `linguist-action` version [e.g. 1.0.1] + +## Additional context -**Additional context** Add any other context about the problem here. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index d2b661f..57be00f 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,8 +1,11 @@ -Closes # + + +Closes #{IssueNumber} ## Pull request checklist Please check if your PR fulfills the following requirements: + - [ ] I have read the [CONTRIBUTING](https://github.com/fabasoad/linguist-action/CONTRIBUTING.md) doc. - [ ] Tests for the changes have been added (for bug fixes / features). - [ ] Docs have been reviewed and added / updated if needed (for bug fixes / features). @@ -10,24 +13,23 @@ Please check if your PR fulfills the following requirements: ## Pull request type - + - + Please check the type of change your PR introduces: + - [ ] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] Documentation content changes -- [ ] Other (please describe): - +- [ ] Other (please describe): ## What is the current behavior? - ## What is the new behavior? @@ -42,7 +44,6 @@ Please check the type of change your PR introduces: - ## Other information diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 0000000..6224cac --- /dev/null +++ b/.github/workflows/create-release.yml @@ -0,0 +1,45 @@ +--- +name: Create release + +on: + push: + branches: + - main + +jobs: + create_release: + name: Release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2.3.4 + with: + fetch-depth: 0 + ref: ${{ github.ref }} + - name: Get commits since last release + id: changes + uses: simbo/changes-since-last-release-action@v1 + - name: Get latest version + id: substring + run: | + ver=$(echo "${{ steps.changes.outputs.last-tag }}" | cut -c2-) + echo '::set-output name=version::'$ver + - name: Increase version + id: semver + uses: matt-FFFFFF/simple-semver@v0.1.0 + with: + semver-input: ${{ steps.substring.outputs.version }} + increment: p + - name: Create release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ steps.semver.outputs.semver }} + release_name: v${{ steps.semver.outputs.semver }} + body: | + # Changes + + ${{ steps.changes.outputs.log }} + draft: false + prerelease: false diff --git a/.github/workflows/dockerfile-lint.yml b/.github/workflows/dockerfile-lint.yml deleted file mode 100644 index 8653454..0000000 --- a/.github/workflows/dockerfile-lint.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Dockerfile Lint - -on: - push: - paths: - - 'Dockerfile' - -jobs: - lint: - name: Lint - timeout-minutes: 3 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2.3.4 - - uses: burdzwastaken/hadolint-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - HADOLINT_ACTION_DOCKERFILE_FOLDER: ./ - HADOLINT_ACTION_COMMENT: false diff --git a/.github/workflows/functional-tests.yml b/.github/workflows/functional-tests.yml index 5b30af6..f7496b8 100644 --- a/.github/workflows/functional-tests.yml +++ b/.github/workflows/functional-tests.yml @@ -21,4 +21,4 @@ jobs: percentage: true - name: Validate linguist result run: | - [[ '{"Ruby":"76.68%","Dockerfile":"19.31%","Shell":"4.01%"}' == '${{ steps.linguist.outputs.data }}' ]] || exit 1; + [[ '{"Ruby":"74.38%","Dockerfile":"20.80%","Shell":"4.83%"}' == '${{ steps.linguist.outputs.data }}' ]] || exit 1; diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..fd4b8c9 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,25 @@ +--- +name: Lint + +on: + push: + branches: + - main + - 'bugfix/**' + - 'feature/**' + +jobs: + build: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v2.3.4 + with: + fetch-depth: 0 + - name: Lint Code Base + uses: github/super-linter@v3.14.3 + env: + VALIDATE_ALL_CODEBASE: true + DEFAULT_BRANCH: main + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ruby-lint.yml b/.github/workflows/ruby-lint.yml deleted file mode 100644 index b3a4229..0000000 --- a/.github/workflows/ruby-lint.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -name: Ruby Lint - -on: - push: - paths: - - '**.rb' - -jobs: - lint: - name: Lint - timeout-minutes: 3 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2.3.4 - - uses: andrewmcodes/rubocop-linter-action@v3.3.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/security-tests.yml b/.github/workflows/security-tests.yml index ee56ce0..be674b4 100644 --- a/.github/workflows/security-tests.yml +++ b/.github/workflows/security-tests.yml @@ -22,4 +22,4 @@ jobs: run: | docker build -t ${{ github.repository }}:${{ github.sha }} . snyk auth ${{ secrets.SNYK_API_TOKEN }} - snyk test --docker ${{ github.repository }}:${{ github.sha }} --file=Dockerfile + snyk test --docker ${{ github.repository }}:${{ github.sha }} --file=Dockerfile --exclude-base-image-vulns diff --git a/.github/workflows/shell-lint.yml b/.github/workflows/shell-lint.yml deleted file mode 100644 index 8b9e8e0..0000000 --- a/.github/workflows/shell-lint.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -name: Shell Lint - -on: - push: - paths: - - '**.sh' - -jobs: - lint: - name: Lint - timeout-minutes: 3 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2.3.4 - - uses: bewuethr/shellcheck-action@v2.0.3 diff --git a/.github/workflows/yaml-lint.yml b/.github/workflows/yaml-lint.yml deleted file mode 100644 index 10addc6..0000000 --- a/.github/workflows/yaml-lint.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -name: YAML Lint - -on: - push: - paths: - - '**.yml' - -jobs: - lint: - name: Lint - timeout-minutes: 3 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2.3.4 - - uses: ibiqlik/action-yamllint@v3.0.0 - with: - config_file: .yamllint.yml - strict: false diff --git a/.gitignore b/.gitignore index e49b575..c7e619f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +.bundle/* +!.bundle/config .vscode/* !.vscode/settings.json \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 3f82bf4..22bf57e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,12 +1,21 @@ { + "editor.codeActionsOnSave": { + "source.fixAll": true + }, "cSpell.words": [ "andrewmcodes", + "appium", "bewuethr", "burdzwastaken", "hadolint", "ibiqlik", "issuehunt", "liberapay", + "markdownlint", + "semver", + "simbo", + "sloc", + "vulns", "yamllint" ] } \ No newline at end of file diff --git a/.yamllint.yml b/.yamllint.yml deleted file mode 100644 index 169fc32..0000000 --- a/.yamllint.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -extends: default - -rules: - line-length: - max: 150 - level: warning diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 626b02a..2874e05 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,5 @@ # Contributing guidance + We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's: - Reporting a bug @@ -8,9 +9,11 @@ We love your input! We want to make contributing to this project as easy and tra - Becoming a maintainer ## We Develop with GitHub + We use GitHub to host code, to track issues and feature requests, as well as accept pull requests. ## We Use [GitHub Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests + Pull requests are the best way to propose changes to the codebase (we use [GitHub Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests: 1. Fork the repo and create your branch from `main`. @@ -21,21 +24,28 @@ Pull requests are the best way to propose changes to the codebase (we use [GitHu 6. Issue that pull request! ## Any contributions you make will be under the MIT Software License + In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern. ## Report bugs using [GitHub Issues](https://github.com/fabasoad/linguist-action/issues) + We use GitHub issues to track public bugs. Report a bug by opening a new issue. It's that easy! ## Create issue using provided GitHub issue templates + This repository has issue templates for bug report and feature request. Please use them to create an issue and fill all required fields. ## Use a Consistent Coding Style + Please follow all the rules from the following documents: + - [Bash coding style](https://github.com/icy/bash-coding-style) provided by [icy](https://github.com/icy). -- [Ruby coding style](https://www.w3resource.com/ruby/ruby-style-guide.php) provided by w3resource. +- [Ruby coding style](https://www.w3resource.com/ruby/ruby-style-guide.php) provided by w3resource. ## License + By contributing, you agree that your contributions will be licensed under its MIT License. ## References -This document was adapted from the open-source contribution guidelines provided by [briandk](https://gist.github.com/briandk/3d2e8b3ec8daf5a27a62). \ No newline at end of file + +This document was adapted from the open-source contribution guidelines provided by [briandk](https://gist.github.com/briandk/3d2e8b3ec8daf5a27a62). diff --git a/Dockerfile b/Dockerfile index d76bd00..c589fea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,8 @@ -FROM ruby:2.7.1-buster +FROM ruby:3.0.0-buster -RUN apt-get update ;\ - apt-get install -y --no-install-recommends cmake=3.13.4-1 ruby-dev=1:2.5.1 ;\ - apt-get clean ;\ - rm -rf /var/lib/apt/lists/* -RUN gem install bundler -v 2.1.4 +RUN apt-get update && apt-get install -y --no-install-recommends cmake=3.13.4-1 ruby-dev=1:2.5.1 ;\ + apt-get clean && rm -rf /var/lib/apt/lists/* +RUN gem install bundler -v 2.2.4 COPY Gemfile /Gemfile RUN bundle install @@ -12,5 +10,4 @@ RUN cat Gemfile.lock COPY linguist.rb /linguist.rb COPY docker-entrypoint.sh / -RUN chmod +x /docker-entrypoint.sh ENTRYPOINT [ "/docker-entrypoint.sh" ] \ No newline at end of file diff --git a/Gemfile b/Gemfile index 909d5ab..5652485 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source 'https://rubygems.org' do - gem 'github-linguist', '7.8.0' + gem 'github-linguist', '7.12.2' end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index bc3f6be..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,21 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - charlock_holmes (0.7.7) - escape_utils (1.2.1) - github-linguist (7.8.0) - charlock_holmes (~> 0.7.6) - escape_utils (~> 1.2.0) - mini_mime (~> 1.0) - rugged (>= 0.25.1) - mini_mime (1.0.2) - rugged (0.99.0) - -PLATFORMS - ruby - -DEPENDENCIES - github-linguist (= 7.8.0)! - -BUNDLED WITH - 2.1.4 \ No newline at end of file diff --git a/README.md b/README.md index ada2df8..dd4515f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ + + # Linguist action -![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/fabasoad/linguist-action?include_prereleases) ![CI (latest)](https://github.com/fabasoad/linguist-action/workflows/CI%20(latest)/badge.svg) ![Functional tests](https://github.com/fabasoad/linguist-action/workflows/Functional%20tests/badge.svg) ![Security tests](https://github.com/fabasoad/linguist-action/workflows/Security%20tests/badge.svg) ![YAML Lint](https://github.com/fabasoad/linguist-action/workflows/YAML%20Lint/badge.svg) ![Ruby Lint](https://github.com/fabasoad/linguist-action/workflows/Ruby%20Lint/badge.svg) ![Dockerfile Lint](https://github.com/fabasoad/linguist-action/workflows/Dockerfile%20Lint/badge.svg) ![Shell Lint](https://github.com/fabasoad/linguist-action/workflows/Shell%20Lint/badge.svg) [![Known Vulnerabilities](https://snyk.io/test/github/fabasoad/linguist-action/badge.svg?targetFile=Gemfile.lock)](https://snyk.io/test/github/fabasoad/linguist-action?targetFile=Gemfile.lock) +![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/fabasoad/linguist-action?include_prereleases) ![CI (latest)](https://github.com/fabasoad/linguist-action/workflows/CI%20(latest)/badge.svg) ![Functional tests](https://github.com/fabasoad/linguist-action/workflows/Functional%20tests/badge.svg) ![Security tests](https://github.com/fabasoad/linguist-action/workflows/Security%20tests/badge.svg) ![Lint](https://github.com/fabasoad/linguist-action/workflows/Lint/badge.svg) [![Known Vulnerabilities](https://snyk.io/test/github/fabasoad/linguist-action/badge.svg?targetFile=Gemfile.lock)](https://snyk.io/test/github/fabasoad/linguist-action?targetFile=Gemfile.lock) This action uses [github/linguist](https://github.com/github/linguist) library to detect language type for a file, or, given a repository, determine language breakdown in JSON format. diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh old mode 100644 new mode 100755 diff --git a/linguist.rb b/linguist.rb index fca583d..6fd8a3b 100644 --- a/linguist.rb +++ b/linguist.rb @@ -1,9 +1,10 @@ #!/usr/bin/env ruby +# frozen_string_literal: false -require 'linguist' -require 'rugged' -require 'json' -require 'optparse' +require "linguist" +require "rugged" +require "json" +require "optparse" path = ARGV[0] || Dir.pwd @@ -14,36 +15,36 @@ rugged = Rugged::Repository.new(path) repo = Linguist::Repository.new(rugged, rugged.head.target_id) - data = Hash.new() - repo.languages.sort_by { |_, size| size }.reverse.each do |language, size| + data = Hash.new + repo.languages.sort_by { |_, size| size }.reverse_each do |language, size| value = (size / repo.size.to_f) if percentage value *= 100 - value = sprintf '%.2f' % value + value = sprintf "%.2f" % value value = "#{value}%" end - data[language] = value + data[language] = value end puts JSON.generate(data) elsif File.file?(path) blob = Linguist::FileBlob.new(path, Dir.pwd) type = if blob.text? - 'Text' + "Text" elsif blob.image? - 'Image' + "Image" else - 'Binary' + "Binary" end + json = Hash.new + json["lines"] = blob.loc + json["sloc"] = blob.sloc + json["type"] = type + json["mime_type"] = blob.mime_type + json["language"] = blob.language puts JSON.generate({ - blob.name => { - :lines => blob.loc, - :sloc => blob.sloc, - :type => type, - :mime_type => blob.mime_type, - :language => blob.language - } + blob.name => json }) else abort <<-HELP @@ -53,4 +54,4 @@ Usage: ruby linguist.rb ruby linguist.rb [percentage] HELP -end \ No newline at end of file +end diff --git a/screenshot.png b/screenshot.png deleted file mode 100644 index c997768..0000000 Binary files a/screenshot.png and /dev/null differ