Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ updates:
directory: "/"
schedule:
interval: "weekly"
groups:
actions:
patterns: ["*"]
- package-ecosystem: "bundler"
directory: "/"
schedule:
interval: "weekly"
groups:
# Lint and type tooling churns often and never affects the shipped gem.
development:
dependency-type: "development"
patterns: ["*"]
runtime:
dependency-type: "production"
patterns: ["*"]
163 changes: 141 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,176 @@
name: CI

on:
push:
branches: [master]
pull_request:
schedule:
# Run every on Friday to ensure everything works as expected.
- cron: '0 6 * * 5'
# Weekly, to catch breakage from new Ruby or Zammad releases.
- cron: '0 6 * * 5'
workflow_dispatch:
inputs:
zammad_ref:
description: 'One Zammad branch or tag to run the integration specs against, in place of the usual three (not a commit SHA)'
default: ''
type: string

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions:
contents: read

jobs:
lint:
name: RuboCop
runs-on: ubuntu-latest
container:
image: zammad/zammad-ci:latest
steps:
- uses: actions/checkout@v7
- name: Run lint actions
shell: bash
run: |
source /etc/profile.d/rvm.sh # ensure RVM is loaded
bundle update --bundler
bundle install -j $(nproc)
bundle exec rubocop
test:
- uses: ruby/setup-ruby@v1
with:
ruby-version: '4.0'
bundler-cache: true
- run: bundle exec rubocop --format github

types:
name: Steep
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ruby/setup-ruby@v1
with:
ruby-version: '4.0'
bundler-cache: true
- run: bundle exec steep check
# sig/vendor is always on the load path here but never in the gem, so
# the published set is checked on its own as well.
- run: bundle exec rake rbs_published

unit:
name: Unit specs (Ruby ${{ matrix.ruby }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Stable releases only, from required_ruby_version up to the current
# stable line. There is no 3.5: that line became 4.0.
ruby: ['3.4', '4.0']
env:
# The unit specs do not need the type-checking toolchain, and skipping it
# keeps this job fast. The `types` job installs it separately.
BUNDLE_WITHOUT: development
steps:
- uses: actions/checkout@v7
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run unit specs
run: bundle exec rake spec:unit
env:
COVERAGE: 'true'

integration:
name: Integration specs (Zammad ${{ matrix.zammad }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# The oldest release line the gem is tested against, the current
# release, and what the next one is being built from.
zammad: ${{ fromJSON(inputs.zammad_ref && format('["{0}"]', inputs.zammad_ref) || '["stable-7.0", "stable", "develop"]') }}
# Booting Zammad costs far more runner time than the unit suite, so there
# is no point paying for it when the unit specs are already failing.
needs: unit
# A full Zammad boot takes many minutes; without a cap a hung boot would
# occupy a runner until the six hour default expires.
timeout-minutes: 45
container:
image: zammad/zammad-ci:latest
services:
postgresql:
image: postgres:17
image: postgres:18
env:
POSTGRES_USER: zammad
POSTGRES_PASSWORD: zammad
redis:
image: redis:7
env:
ZAMMAD_REF: ${{ matrix.zammad }}
TEST_USER: admin@example.com
TEST_PASSWORD: test
steps:
- uses: actions/checkout@v7
- name: Set up Zammad

- name: Boot Zammad
shell: bash
run: |
git clone --depth 1 https://github.com/zammad/zammad.git
# No `set -u`: /etc/profile.d/rvm.sh reads unset variables and aborts
# under nounset.
set -eo pipefail
git clone --depth 1 --branch "$ZAMMAD_REF" https://github.com/zammad/zammad.git
cd zammad
source /etc/profile.d/rvm.sh # ensure RVM is loaded
source /etc/profile.d/rvm.sh
# The image ships the Ruby of Zammad's develop branch. A release
# names an older one, which is built here; installing the one that
# is there already does nothing. The specs themselves run on the
# image's Ruby, in the steps below.
zammad_ruby="$(cat .ruby-version)"
# Where rvm unpacks a Ruby to build it, which the image leaves out.
mkdir -p "$rvm_path/src"
if ! rvm install "$zammad_ruby" || ! rvm use "$zammad_ruby"; then
echo "::error::could not provide Ruby $zammad_ruby for Zammad $ZAMMAD_REF"
exit 1
fi
bundle config set --local frozen 'true'
bundle config set --local path 'vendor'
bundle install -j $(nproc)
bundle install -j "$(nproc)"
bundle exec ruby .gitlab/configure_environment.rb
source .gitlab/environment.env
RAILS_ENV=test bundle exec rake db:create
cp contrib/auto_wizard_test.json auto_wizard.json
bundle exec rake zammad:ci:test:start
- name: Run Ruby API integration tests
echo "TEST_URL=http://localhost:3000/" >> "$GITHUB_ENV"

- name: Wait for Zammad to answer
shell: bash
run: |
probe="${TEST_URL%/}/api/v1/getting_started"
for attempt in $(seq 1 60); do
if curl -sSf --max-time 5 "$probe" >/dev/null 2>&1; then
echo "Zammad answered at $TEST_URL after ${attempt} attempt(s)"
exit 0
fi
sleep 5
done
echo "::error::Zammad never answered at $probe"
exit 1

- name: Install the gem's dependencies
shell: bash
run: |
source /etc/profile.d/rvm.sh
bundle install -j "$(nproc)"

- name: Run the integration specs
shell: bash
run: |
source /etc/profile.d/rvm.sh
bundle exec rake spec:integration

- name: Collect Zammad logs on failure
if: failure()
shell: bash
run: |
source /etc/profile.d/rvm.sh # ensure RVM is loaded
bundle update --bundler
bundle install -j $(nproc)
bundle exec rspec
echo '--- zammad/log ---'
tail -n 200 zammad/log/*.log 2>/dev/null || echo 'no logs found'

- name: Upload Zammad logs
if: failure()
uses: actions/upload-artifact@v7
with:
name: zammad-logs-${{ matrix.zammad }}
path: zammad/log/
if-no-files-found: ignore
retention-days: 7
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release

# Publishes to RubyGems via trusted publishing (OIDC), so no API key is
# stored in this repository. Configure the trusted publisher once at
# https://rubygems.org/gems/zammad_api/trusted_publishers
on:
push:
tags: ['v*']

permissions:
contents: read

jobs:
release:
name: Build and publish
runs-on: ubuntu-latest
environment: rubygems
permissions:
contents: write # `rake release`, which the release action runs, pushes the tag
id-token: write # request the OIDC token for trusted publishing
steps:
- uses: actions/checkout@v7
- uses: ruby/setup-ruby@v1
with:
ruby-version: '4.0'
bundler-cache: true
# The tag is what triggers this workflow, and nothing downstream reads
# it: the gem is built from the gemspec, so a tag that disagrees with
# ZammadAPI::VERSION would publish a gem under a version nobody tagged.
- name: Check the tag against the gem version and the changelog
run: |
tagged="${GITHUB_REF_NAME#v}"
declared="$(ruby -Ilib -rzammad_api/version -e 'print ZammadAPI::VERSION')"
if [ "$tagged" != "$declared" ]; then
echo "::error::tag ${GITHUB_REF_NAME} does not match ZammadAPI::VERSION ($declared)"
exit 1
fi
if ! grep -q "^## \[${declared}\]" CHANGELOG.md; then
echo "::error::CHANGELOG.md has no '## [${declared}]' heading"
exit 1
fi
- name: Verify the release candidate
run: bundle exec rake
- uses: rubygems/release-gem@v1
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/.bundle/
/.ruby-version
/.yardoc
/.steep/
/.yardoc/
/_yardoc/
/coverage/
/doc/
Expand Down
50 changes: 20 additions & 30 deletions .overcommit.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
# Use this file to configure the Overcommit hooks you wish to use. This will
# extend the default configuration defined in:
# https://github.com/sds/overcommit/blob/master/config/default.yml
# See https://github.com/sds/overcommit#configuration
#
# At the topmost level of this YAML file is a key representing type of hook
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
# customize each hook, such as whether to only run it on certain files (via
# `include`), whether to only display output if it fails (via `quiet`), etc.
#
# For a complete list of hooks, see:
# https://github.com/sds/overcommit/tree/master/lib/overcommit/hook
#
# For a complete list of options that you can use to customize hooks, see:
# https://github.com/sds/overcommit#configuration
#
# Uncomment the following lines to make the configuration take effect.
# Install with: bundle exec overcommit --install

PreCommit:
RuboCop:
enabled: true
on_warn: fail # Treat all warnings as failures
#
# TrailingWhitespace:
# enabled: true
# exclude:
# - '**/db/structure.sql' # Ignore trailing whitespace in generated files
#
#PostCheckout:
# ALL: # Special hook name that customizes all hooks of this type
# quiet: true # Change all post-checkout hooks to only display output on failure
#
# IndexTags:
# enabled: true # Generate a tags file with `ctags` each time HEAD changes
RuboCop:
enabled: true
on_warn: fail # Treat all warnings as failures
command: ['bundle', 'exec', 'rubocop']

TrailingWhitespace:
enabled: true

YamlSyntax:
enabled: true

BundleCheck:
enabled: true

RSpec:
enabled: true
description: 'Run the unit specs'
command: ['bundle', 'exec', 'rspec', 'spec/unit']
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--require spec_helper
--format documentation
--color
Loading