aboutsummaryrefslogtreecommitdiffstats
path: root/.github/workflows/ruby.yml
blob: 8ec504edfa0941f4f04ac46b58059420e7fab2fd (plain) (blame)
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
name: Ruby

on:
  push:
    paths:
      - "**.rb"
      - "**.gemspec"
      - "Gemfile"
      - "Gemfile.lock"
      - "Rakefile"
      - ".github/workflows/ruby.yml"
  pull_request:
    paths:
      - "**.rb"
      - "**.gemspec"
      - "Gemfile"
      - "Gemfile.lock"
      - "Rakefile"
      - ".github/workflows/ruby.yml"

jobs:
  lint-build-and-test:
    runs-on: ubuntu-latest
    name: Ruby
    steps:
    - uses: actions/checkout@v4
    - name: Set up Ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: ruby
        bundler-cache: true
    - name: Lint, Build and Test with Rake
      run: bundle exec rake

  publish-preview:
    runs-on: ubuntu-latest
    needs: lint-build-and-test
    if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
    name: Publish Preview to GitHub Package Registry
    permissions:
      packages: write
      contents: read
    steps:
    - uses: actions/checkout@v4
    - name: Set version to pre-release
      run: |
        sed "s/$(jq -r .version package.json)/$(jq -r .version package.json).pre/" locusts.gemspec -i
        sed "s/$(jq -r .version package.json)/$(jq -r .version package.json).pre/" Gemfile.lock -i
    - name: Set up Ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: ruby
        bundler-cache: true
    - name: Build gem
      run: bundle exec rake build
    - name: Set up GitHub Package Registry for RubyGems
      run: |
        mkdir -p ~/.gem
        touch ~/.gem/credentials
        chmod 0600 ~/.gem/credentials
        echo ":github: Bearer ${{ secrets.GITHUB_TOKEN }}" >> ~/.gem/credentials
    - name: Publish gem
      run: gem push --key github --host https://rubygems.pkg.github.com/locusts-r-us pkg/*.gem

  publish-release:
    name: Push gem to RubyGems.org
    needs: lint-build-and-test
    # Only run on this on proper semver (vX.Y.Z) tags
    if: ${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }}
    runs-on: ubuntu-latest
    permissions:
      id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
    steps:
      # Set up
      - uses: actions/checkout@v4
      - name: Set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true
          ruby-version: ruby
      - name: Build gem
        run: bundle exec rake build
      - name: Publish gem
        uses: rubygems/release-gem@v1