summaryrefslogtreecommitdiff
path: root/.github/workflows/kitchen.yml
blob: 260267a418be6fd4b136be55ef869ab0d7cf08a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
---
name: kitchen

"on":
  pull_request:
  push:
    branches:
      - main

jobs:
  windows:
    strategy:
      fail-fast: false
      matrix:
        os: [windows-2022, windows-2019]
        ruby: ['3.1']
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v3
    - name: 'Upgrade Ruby Devkit on Windows'
      id: upgrade_ruby
      run: |
        $pkg_version="3.1.2"
        $pkg_revision="1"
        $pkg_source="https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-${pkg_version}-${pkg_revision}/rubyinstaller-devkit-${pkg_version}-${pkg_revision}-x64.exe"

        $old_version = Ruby --version
        if(-not($old_version -match "3.1")){
          $ErrorActionPreference = 'Stop';
          Write-Output 'Downloading Ruby + DevKit';
          [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
          $package_destination = "$env:temp\rubyinstaller-devkit-$pkg_version-$pkg_revision-x64.exe"
          (New-Object System.Net.WebClient).DownloadFile($pkg_source, $package_destination);
          Write-Output "Did the file download?"
          $output = Get-ChildItem -Path $env:temp
          Write-Output $output
          Write-Output 'Installing Ruby + DevKit';
          Start-Process $package_destination -ArgumentList '/verysilent /dir=C:\ruby31' -Wait ;
          Write-Output 'Cleaning up installation';
          Remove-Item $package_destination -Force;
          Write-Output "Installing URU to manage Ruby Versions"
          choco install 7zip -y
          Write-Output "Downloading Uru Installer..."
          New-Item -Path c:\uru_temp -Type Directory
          # Use TLS 1.2 for Windows 2016 Server and older
          [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
          Invoke-WebRequest -OutFile "c:\uru_temp\uru-0.8.5-windows-x86.7z" -Uri "https://bitbucket.org/jonforums/uru/downloads/uru-0.8.5-windows-x86.7z"
          Write-Output "Installing Uru Ruby Switcher"
          7z x "c:\uru_temp\uru-0.8.5-windows-x86.7z" -o"C:\Program Files (x86)\Uru"
          If ($lastexitcode -ne 0) { Exit $lastexitcode }
          Start-Process "C:\Program Files (x86)\Uru\uru_rt.exe" -WorkingDirectory "C:\Program Files (x86)\Uru\" -ArgumentList 'admin install' -Wait

          Write-Output 'Updating PATH'
          $env:PATH = "C:\Program Files (x86)\Uru;" + $env:PATH
          [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine)

          Write-Output "Register Installed Ruby Version 3.1 With Uru"
          Start-Process "uru_rt.exe" -ArgumentList 'admin add C:\ruby31\bin' -Wait
          uru 312
          if (-not $?) { throw "Can't Activate Ruby. Did Uru Registration Succeed?" }
          ruby -v
          if (-not $?) { throw "Can't run Ruby. Is it installed?" }
        }

    - name: 'Install Chef/Ohai from Omnitruck'
      id: install_chef
      run: |
        . { Invoke-WebRequest -useb https://omnitruck.chef.io/install.ps1 } | Invoke-Expression; Install-Project -project chef -channel current
        $env:PATH = "C:\ruby31\bin;C:\opscode\chef\bin;C:\opscode\chef\embedded\bin;" + $env:PATH
        chef-client -v
        ohai -v
        rake --version
        bundle -v
    - name: 'Upgrade Chef/Ohai via Appbundler'
      id: upgrade
      run: |
        $env:PATH = "C:\opscode\chef\bin;C:\opscode\chef\embedded\bin;" + $env:PATH
        $env:OHAI_VERSION = ( Select-String -Path .\Gemfile.lock -Pattern '(?<=ohai \()\d.*(?=\))' | ForEach-Object { $_.Matches[0].Value } )

        # The chef-client installer does not put the file 'ansidecl.h' down in the correct location
        # This leads to failures during testing. Moving that file to its correct position here.
        # Another example of 'bad' that needs to be corrected
        $output = gci -path C:\opscode\ -file ansidecl.h -Recurse

        # As of Ruby 3.1, there are 3 ansidecl.h files found in the opscode path
        # Grabbing the first (and shortest) path found is a bit of a :fingers-crossed: but
        # making the leap that ansidecl.h isn't going to vary in a way that will fail
        # subtly.
        if ($output -is [Array]) { $output = $output[0] }

        $target_path = $($output.Directory.Parent.FullName + "\x86_64-w64-mingw32\include")
        Move-Item -Path $output.FullName -Destination $target_path

        gem install appbundler appbundle-updater --no-doc
        If ($lastexitcode -ne 0) { Exit $lastexitcode }
        appbundle-updater chef chef $env:GITHUB_SHA --tarball --github $env:GITHUB_REPOSITORY
        If ($lastexitcode -ne 0) { Exit $lastexitcode }
        Write-Output "Installed Chef / Ohai release:"
        chef-client -v
        If ($lastexitcode -ne 0) { Exit $lastexitcode }
        ohai -v
        If ($lastexitcode -ne 0) { Exit $lastexitcode }
    - name: 'Run end_to_end::default recipe'
      id: run
      run: |
        cd kitchen-tests
        $env:PATH = "C:\ruby31\bin;C:\opscode\chef\bin;C:\opscode\chef\embedded\bin;" + $env:PATH
        # htmldiff and ldiff on windows cause a conflict with gems being loaded below.
        # we remove thenm here.
        if (Test-Path C:\opscode\chef\embedded\bin\htmldiff)
        {
            Remove-Item -Path C:\opscode\chef\embedded\bin\htmldiff
            Remove-Item -Path C:\opscode\chef\embedded\bin\ldiff
        }

        bundle install --jobs=3 --retry=3
        # If ($lastexitcode -ne 0) { Exit $lastexitcode }
        # The bundle install command above fails because our build on windows on ruby-3.0 is
        # completely broken when it comes to installing native gems.  Until that is fixed we
        # need to ignore that error code and to manually install berkshelf below.  This is a
        # very bad hack.

        If ($lastexitcode -ne 0) { Exit $lastexitcode }
        gem install berkshelf --no-doc
        If ($lastexitcode -ne 0) { Exit $lastexitcode }
        berks vendor cookbooks
        If ($lastexitcode -ne 0) { Exit $lastexitcode }
        chef-client -z -o end_to_end --chef-license accept-no-persist

  macos:
    strategy:
      fail-fast: false
      matrix:
        os: [macos-latest]
        ruby: ["3.1"] # macos-11.0 is not public for now
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v3
      with:
        clean: true
    - name: 'Upgrade Ruby Devkit on Macos'
      id: upgrade_ruby
      run: |
        echo "This is the installed version of Ruby:"
        brew info ruby
    - name: 'Install Chef Foundation from Omnitruck'
      id: install_chef
      run: |
        brew install coreutils
        curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -c current -P "chef-foundation"
    - name: 'Run end_to_end::default recipe'
      id: run
      run: |
        export PATH="/opt/chef/bin:/opt/chef/embedded/bin:$PATH"
        echo "which bundler are we using?"
        which bundle
        echo "what version is that?"
        bundle --version
        cd /Users/runner/work/chef/chef
        sudo bundle install
        cd kitchen-tests
        sudo bundle install --jobs=3 --retry=3
        sudo gem install kitchen
        sudo gem install berkshelf --no-doc
        sudo berks vendor cookbooks
        sudo /opt/chef/bin/chef-client -z -o end_to_end --chef-license accept-no-persist

  linux:
    strategy:
      fail-fast: false
      matrix:
        os:
          - 'amazonlinux-2'
          - 'centos-6'
          - 'centos-7'
          - 'almalinux-8'
          - 'debian-9'
          - 'debian-10'
          - 'debian-11'
          - 'fedora-latest'
          - 'opensuse-leap-15'
          - 'ubuntu-1804'
          - 'ubuntu-2004'
          - 'ubuntu-2204'
        ruby: ['3.1']
    runs-on: ubuntu-latest
    env:
      FORCE_FFI_YAJL: ext
      CHEF_LICENSE: accept-no-persist
    steps:
      - name: Check out code
        uses: actions/checkout@v3
      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: "3.1"
          bundler-cache: false
          working-directory: kitchen-tests
      - name: Run Test Kitchen
        working-directory: kitchen-tests
        run:  |
          ruby -v
          echo "Which ruby are we using?"
          which ruby
          cd /home/runner/work/chef/chef
          bundle install
          gem install kitchen
          cd /home/runner/work/chef/chef/kitchen-tests
          bundle install
          bundle exec kitchen test end-to-end-${{ matrix.os }}