diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a88a8386..f16239e0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,84 +1,58 @@ -name: CI +name: "ci" on: pull_request: branches: - - main + - "main" schedule: - cron: "0 0 * * *" workflow_dispatch: jobs: - rubocop: + spec: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: - - windows-latest - - ubuntu-latest - ruby: ["2.7"] + - "ubuntu-latest" + ruby: + - 2.5 + - 2.7 + steps: - - name: Checkout Source - uses: actions/checkout@v3 + - name: "checkout" + uses: "actions/checkout@v3" - - name: Activate Ruby - uses: ruby/setup-ruby@v1 + - name: "setup ruby" + uses: "ruby/setup-ruby@v1" with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - name: Print Test Environment + - name: "bundle environment" run: | - ruby -v - gem -v - bundle -v - pwsh -v + echo ::group::bundler environment + bundle env + echo ::endgroup:: - - name: Run Rubocop Tests + - name: "rubocop" run: | - bundle exec rake rubocop + bundle exec rubocop - spec: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - windows-latest - - windows-2016 - - ubuntu-latest - - ubuntu-20.04 - ruby: ["2.5", "2.7"] - steps: - - name: Checkout Source - uses: actions/checkout@v3 - - - name: Activate Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - - name: Print Test Environment - run: | - ruby -v - gem -v - bundle -v - pwsh -v - - - name: Run Spec Tests + - name: "spec" run: | bundle exec rake spec - acceptance-dsc: + acceptance: + needs: "spec" runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: - - windows-latest - - windows-2016 + - "windows-latest" + - "windows-2019" puppet: - 6 - 7 @@ -89,25 +63,25 @@ jobs: ruby: 2.7 env: PUPPET_GEM_VERSION: ${{ matrix.puppet }} + steps: - - name: Checkout Source - uses: actions/checkout@v3 + - name: "checkout" + uses: "actions/checkout@v3" - - name: Activate Ruby - uses: ruby/setup-ruby@v1 + - name: "setup ruby" + uses: "ruby/setup-ruby@v1" with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - name: Print Test Environment + - name: "bundle environment" run: | - ruby -v - gem -v - bundle -v - pwsh -v + echo ::group::bundler environment + bundle env + echo ::endgroup:: - - name: Ensure WinRM is working - shell: powershell + - name: "setup winrm" + shell: "powershell" run: | Get-ChildItem WSMan:\localhost\Listener\ -OutVariable Listeners | Format-List * -Force $HTTPListener = $Listeners | Where-Object -FilterScript { $_.Keys.Contains('Transport=HTTP') } @@ -116,8 +90,8 @@ jobs: winrm e winrm/config/listener } - - name: Run Acceptance Tests - shell: powershell + - name: "acceptance" + shell: "powershell" run: | bundle exec rake dsc:acceptance:spec_prep bundle exec rake dsc:acceptance:spec diff --git a/.github/workflows/labeller.yml b/.github/workflows/labeller.yml index 517ea396..975e68eb 100644 --- a/.github/workflows/labeller.yml +++ b/.github/workflows/labeller.yml @@ -1,21 +1,21 @@ -name: community-labeller +name: "community-labeller" on: issues: types: - - opened + - "opened" pull_request_target: types: - - opened + - "opened" jobs: label: - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" steps: - - uses: puppetlabs/community-labeller@v0 - name: Label issues or pull requests + - uses: "puppetlabs/community-labeller@v0" + name: "Label issues or pull requests" with: - label_name: community - label_color: '5319e7' - org_membership: puppetlabs + label_name: "community" + label_color: "5319e7" + org_membership: "puppetlabs" token: ${{ secrets.IAC_COMMUNITY_LABELER }} diff --git a/.github/workflows/publish.yml b/.github/workflows/release.yml similarity index 57% rename from .github/workflows/publish.yml rename to .github/workflows/release.yml index 296e27cd..e78ac0fe 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/release.yml @@ -1,80 +1,82 @@ -name: "Publish" +name: "release" on: workflow_dispatch: jobs: - create-github-release: - name: Deploy GitHub Release - runs-on: ubuntu-20.04 + github-release: + name: "create release" + runs-on: "ubuntu-latest" + if: github.repository_owner == 'puppetlabs' + steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: "checkout" + uses: "actions/checkout@v3" with: ref: ${{ github.ref }} clean: true fetch-depth: 0 - - name: Get Version - id: get_version + - name: "get version" + id: "get_version" run: | echo "::set-output name=version::$(jq --raw-output .version metadata.json)" - - name: Create Release + - name: "create release" run: | - gh release create "${{ steps.get_version.outputs.version" + gh release create "${{ steps.get_version.outputs.version }}" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} publish-gem: - name: Deploy to rubygems - runs-on: ubuntu-20.04 - needs: create-github-release + name: "publish gem" + runs-on: "ubuntu-latest" + needs: "github-release" steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: "checkout" + uses: "actions/checkout@v3" with: ref: ${{ github.ref }} clean: true fetch-depth: 0 - - name: Activate Ruby + - name: "setup ruby" uses: ruby/setup-ruby@v1 with: ruby-version: 2.7 bundler-cache: true - - name: Bundle Install - run: | - bundle install - - - name: Build Gem + - name: "build" run: | bundle exec rake build - - name: Publish Gem + - name: "publish" run: | bundle exec rake push env: GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }} publish-module: - name: Deploy to Forge + name: "publish module" runs-on: ubuntu-20.04 needs: publish-gem steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: "checkout" + uses: "actions/checkout@v3" with: ref: ${{ github.ref }} clean: true - - name: "PDK Build" - uses: docker://puppet/pdk:latest + - name: "update readme" + run: | + mv pwshlib.md README.md + + - name: "build" + uses: "docker://puppet/pdk:latest" with: args: 'build' - - name: "Push to Forge" - uses: docker://puppet/pdk:latest + - name: "publish" + uses: "docker://puppet/pdk:latest" with: args: 'release publish --forge-token ${{ secrets.FORGE_API_KEY }} --force' diff --git a/.github/workflows/release_prep.yml b/.github/workflows/release_prep.yml new file mode 100644 index 00000000..2f6a1707 --- /dev/null +++ b/.github/workflows/release_prep.yml @@ -0,0 +1,16 @@ +name: "release prep" + +on: + workflow_dispatch: + inputs: + target: + description: "The target for the release. This can be a commit sha or a branch." + required: false + default: "main" + +jobs: + release_prep: + uses: "puppetlabs/cat-github-actions/.github/workflows/gem_release_prep.yml@main" + with: + target: "${{ github.event.inputs.target }}" + secrets: "inherit" diff --git a/Rakefile b/Rakefile index c97ef325..663ae18f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'bundler/gem_tasks' require 'rubocop/rake_task' require 'fileutils' require 'github_changelog_generator/task' @@ -44,61 +45,6 @@ task default: :spec YARD::Rake::YardocTask.new do |t| end - -# Executes a command locally. -# -# @param command [String] command to execute. -# @return [Object] the standard out stream. -def run_local_command(command) - stdout, stderr, status = Open3.capture3(command) - error_message = "Attempted to run\ncommand:'#{command}'\nstdout:#{stdout}\nstderr:#{stderr}" - raise error_message unless status.to_i.zero? - - stdout -end - -# Build the gem -desc 'Build the gem' -task :build do - gemspec_path = File.join(Dir.pwd, 'ruby-pwsh.gemspec') - run_local_command("bundle exec gem build '#{gemspec_path}'") -end - -# Tag the repo with a version in preparation for the release -# -# @param :version [String] a semantic version to tag the code with -# @param :sha [String] the sha at which to apply the version tag -desc 'Tag the repo with a version in preparation for release' -task :tag, [:version, :sha] do |_task, args| - raise "Invalid version #{args[:version]} - must be like '1.2.3'" unless args[:version] =~ /^\d+\.\d+\.\d+$/ - - run_local_command('git fetch upstream') - run_local_command("git tag -a #{args[:version]} -m #{args[:version]} #{args[:sha]}") - run_local_command('git push upstream --tags') -end - -# Push the built gem to RubyGems -# -# @param :path [String] optional, the full or relative path to the built gem to be pushed -desc 'Push to RubyGems' -task :push, [:path] do |_task, args| - raise 'No discoverable gem for pushing' if Dir.glob("ruby-pwsh*\.gem").empty? && args[:path].nil? - raise "No file found at specified path: '#{args[:path]}'" unless File.exist?(args[:path]) - - path = args[:path] || File.join(Dir.pwd, Dir.glob("ruby-pwsh*\.gem")[0]) - run_local_command("bundle exec gem push #{path}") -end - -desc 'Build for Puppet' -task :build_module do - actual_readme_content = File.read('README.md') - FileUtils.copy_file('pwshlib.md', 'README.md') - # Build - run_local_command('pdk build --force') - # Cleanup - File.open('README.md', 'wb') { |file| file.write(actual_readme_content) } -end - # Used in vendor_dsc_module TAR_LONGLINK = '././@LongLink' diff --git a/ruby-pwsh.gemspec b/ruby-pwsh.gemspec index e21b569c..645d0d44 100644 --- a/ruby-pwsh.gemspec +++ b/ruby-pwsh.gemspec @@ -18,7 +18,6 @@ Gem::Specification.new do |spec| # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' # to allow pushing to a single host or delete this section to allow pushing to any host. if spec.respond_to?(:metadata) - spec.metadata['homepage_uri'] = spec.homepage spec.metadata['source_code_uri'] = 'https://github.com/puppetlabs/ruby-pwsh' spec.metadata['changelog_uri'] = 'https://github.com/puppetlabs/ruby-pwsh' @@ -27,11 +26,14 @@ Gem::Specification.new do |spec| 'public gem pushes.' end - # Specify which files should be added to the gem when it is released. - # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - spec.files = Dir.chdir(File.expand_path(__dir__)) do - `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - end + spec.files = Dir[ + 'README.md', + 'LICENSE', + '.rubocop.yml', + 'lib/**/*', + 'bin/**/*', + 'spec/**/*', + ] spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } diff --git a/spec/unit/pwsh_spec.rb b/spec/unit/pwsh_spec.rb index ac2e8514..149148f2 100644 --- a/spec/unit/pwsh_spec.rb +++ b/spec/unit/pwsh_spec.rb @@ -401,14 +401,11 @@ def close_stream(stream, style = :inprocess) context 'it should handle UTF-8' do # different UTF-8 widths - # rubocop:disable Style/AsciiComments # 1-byte A # 2-byte ۿ - http://www.fileformat.info/info/unicode/char/06ff/index.htm - 0xDB 0xBF / 219 191 # 3-byte ᚠ - http://www.fileformat.info/info/unicode/char/16A0/index.htm - 0xE1 0x9A 0xA0 / 225 154 160 # 4-byte 𠜎 - http://www.fileformat.info/info/unicode/char/2070E/index.htm - 0xF0 0xA0 0x9C 0x8E / 240 160 156 142 let(:mixed_utf8) { "A\u06FF\u16A0\u{2070E}" } # Aۿᚠ𠜎 - # rubocop:enable Style/AsciiComments - it 'when writing basic text' do code = "Write-Output '#{mixed_utf8}'" result = manager.execute(code)