Skip to content

Commit

Permalink
Merge pull request #197 from puppetlabs/maint-update_ci
Browse files Browse the repository at this point in the history
(MAINT) CI Updates
  • Loading branch information
LukasAud authored Dec 19, 2022
2 parents baac86c + 5eda23d commit 7067ad5
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 164 deletions.
98 changes: 36 additions & 62 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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') }
Expand All @@ -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
18 changes: 9 additions & 9 deletions .github/workflows/labeller.yml
Original file line number Diff line number Diff line change
@@ -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 }}
60 changes: 31 additions & 29 deletions .github/workflows/publish.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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'
16 changes: 16 additions & 0 deletions .github/workflows/release_prep.yml
Original file line number Diff line number Diff line change
@@ -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"
56 changes: 1 addition & 55 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rubocop/rake_task'
require 'fileutils'
require 'github_changelog_generator/task'
Expand Down Expand Up @@ -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'

Expand Down
Loading

0 comments on commit 7067ad5

Please sign in to comment.