From 54e947f05fb4530d64378cb233f6454ae6534c38 Mon Sep 17 00:00:00 2001 From: Phil Helm Date: Wed, 22 Jul 2026 20:36:41 +0100 Subject: [PATCH 1/2] migrate pipeline from circleci to github actions --- .circleci/config.yml | 183 ------------------ {.circleci => .github}/gpg.private.enc | Bin .github/workflows/main.yaml | 135 +++++++++++++ .github/workflows/pr.yaml | 115 +++++++++++ Gemfile | 2 +- Gemfile.lock | 81 ++++---- README.md | 8 +- Rakefile | 156 ++++++++++----- config/secrets/ci/ssh.private | Bin 3265 -> 0 bytes config/secrets/ci/ssh.public | Bin 773 -> 0 bytes config/secrets/circle_ci/config.yaml | Bin 120 -> 0 bytes config/secrets/github/config.yaml | Bin 152 -> 0 bytes scripts/ci/common/configure-asdf.sh | 18 -- scripts/ci/common/configure-git.sh | 8 - scripts/ci/common/configure-rubygems.sh | 2 - .../ci/common/install-asdf-dependencies.sh | 12 -- scripts/ci/common/install-asdf.sh | 19 -- scripts/ci/common/install-git-crypt.sh | 4 +- scripts/ci/common/install-gpg-key.sh | 19 -- scripts/ci/common/install-slack-deps.sh | 8 - scripts/ci/steps/build.sh | 12 -- scripts/ci/steps/merge-pull-request.sh | 16 -- scripts/ci/steps/prerelease.sh | 16 -- scripts/ci/steps/release.sh | 18 -- scripts/ci/steps/test.sh | 12 -- 25 files changed, 412 insertions(+), 432 deletions(-) delete mode 100644 .circleci/config.yml rename {.circleci => .github}/gpg.private.enc (100%) create mode 100644 .github/workflows/main.yaml create mode 100644 .github/workflows/pr.yaml delete mode 100644 config/secrets/ci/ssh.private delete mode 100644 config/secrets/ci/ssh.public delete mode 100644 config/secrets/circle_ci/config.yaml delete mode 100644 config/secrets/github/config.yaml delete mode 100755 scripts/ci/common/configure-asdf.sh delete mode 100755 scripts/ci/common/configure-git.sh delete mode 100755 scripts/ci/common/install-asdf-dependencies.sh delete mode 100755 scripts/ci/common/install-asdf.sh delete mode 100755 scripts/ci/common/install-gpg-key.sh delete mode 100755 scripts/ci/common/install-slack-deps.sh delete mode 100755 scripts/ci/steps/build.sh delete mode 100755 scripts/ci/steps/merge-pull-request.sh delete mode 100755 scripts/ci/steps/prerelease.sh delete mode 100755 scripts/ci/steps/release.sh delete mode 100755 scripts/ci/steps/test.sh diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index f43d4e2..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,183 +0,0 @@ -version: 2.1 - -orbs: - slack: circleci/slack@4.13.2 - -base_container: &base_container - image: buildpack-deps:buster - -build_container: &build_container - resource_class: arm.medium - docker: - - <<: *base_container - -slack_context: &slack_context - context: - - slack - -only_main: &only_main - filters: - branches: - only: - - main - -only_dependabot: &only_dependabot - filters: - branches: - only: - - /^dependabot.*/ - -only_main_and_dependabot: &only_main_and_dependabot - filters: - branches: - only: - - main - - /^dependabot.*/ - -commands: - notify: - steps: - - when: - condition: - matches: - pattern: "^dependabot.*" - value: << pipeline.git.branch >> - steps: - - slack/notify: - event: fail - channel: builds-dependabot - template: SLACK_FAILURE_NOTIFICATION - - slack/notify: - event: pass - channel: builds-dependabot - template: SLACK_SUCCESS_NOTIFICATION - - when: - condition: - matches: - pattern: "^(?!dependabot).*" - value: << pipeline.git.branch >> - steps: - - slack/notify: - event: fail - channel: dev - template: SLACK_FAILURE_NOTIFICATION - - slack/notify: - event: pass - channel: builds - template: SLACK_SUCCESS_NOTIFICATION - - configure_build_tools: - steps: - - run: ./scripts/ci/common/install-slack-deps.sh - - restore_cache: - keys: - - asdf-dependencies-{{ arch }}-v2-{{ checksum ".tool-versions" }} - - asdf-dependencies-{{ arch }}-v2- - - run: ./scripts/ci/common/install-asdf.sh - - run: ./scripts/ci/common/configure-asdf.sh - - run: ./scripts/ci/common/install-asdf-dependencies.sh - - save_cache: - key: asdf-dependencies-{{ arch }}-v2-{{ checksum ".tool-versions" }} - paths: - - ~/.asdf - - configure_secrets_tools: - steps: - - run: ./scripts/ci/common/install-git-crypt.sh - - run: ./scripts/ci/common/install-gpg-key.sh - - run: ./scripts/ci/common/configure-git.sh - - configure_release_tools: - steps: - - add_ssh_keys: - fingerprints: - - "SHA256:FBsNLH/GlPX3s4wWMB0CGsH5Mam0IpyL7DlQ4qNIM9c" - - run: ./scripts/ci/common/configure-rubygems.sh - - configure_tools: - steps: - - configure_build_tools - - configure_secrets_tools - - configure_release_tools - -jobs: - build: - <<: *build_container - steps: - - checkout - - configure_tools - - run: ./scripts/ci/steps/build.sh - - notify - - test: - <<: *build_container - steps: - - checkout - - configure_tools - - run: ./scripts/ci/steps/test.sh - - notify - - prerelease: - <<: *build_container - steps: - - checkout - - configure_tools - - run: ./scripts/ci/steps/prerelease.sh - - notify - - release: - <<: *build_container - steps: - - checkout - - configure_tools - - run: ./scripts/ci/steps/release.sh - - notify - - merge_pull_request: - <<: *build_container - steps: - - checkout - - configure_tools - - run: ./scripts/ci/steps/merge-pull-request.sh - - notify - -workflows: - version: 2 - pipeline: - jobs: - - build: - <<: *only_main_and_dependabot - <<: *slack_context - - test: - <<: *only_main_and_dependabot - <<: *slack_context - requires: - - build - - merge_pull_request: - <<: *only_dependabot - <<: *slack_context - requires: - - test - - prerelease: - <<: *only_main - <<: *slack_context - requires: - - test - - slack/on-hold: - <<: *only_main - <<: *slack_context - requires: - - prerelease - channel: release - template: SLACK_ON_HOLD_NOTIFICATION - - hold: - <<: *only_main - type: approval - requires: - - prerelease - - slack/on-hold - - release: - <<: *only_main - <<: *slack_context - requires: - - hold diff --git a/.circleci/gpg.private.enc b/.github/gpg.private.enc similarity index 100% rename from .circleci/gpg.private.enc rename to .github/gpg.private.enc diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..31093ce --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,135 @@ +name: Main +on: + push: + branches: + - main + +permissions: + contents: read + +jobs: + check: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - name: Install tools + uses: infrablocks/github-actions/asdf_install@v1 + - name: Check + run: ./go library:check + - name: Notify Slack + if: ${{ !cancelled() }} + continue-on-error: true + run: ./go "slack:notify[${{ job.status }}]" + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + + test: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - name: Install tools + uses: infrablocks/github-actions/asdf_install@v1 + - name: Test + run: ./go spec + - name: Notify Slack + if: ${{ !cancelled() }} + continue-on-error: true + run: ./go "slack:notify[${{ job.status }}]" + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + + prerelease: + needs: [check, test] + runs-on: ubuntu-latest + timeout-minutes: 30 + # Job-level group (here and on release): a run awaiting release approval + # holds the slot, and a workflow-level group would freeze all main CI for + # the approval window. queue: max keeps every queued run; the default + # cancels all but the newest. + concurrency: + group: main + cancel-in-progress: false + queue: max + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - name: Install tools + uses: infrablocks/github-actions/asdf_install@v1 + - name: Install secrets tools + run: ./scripts/ci/common/install-git-crypt.sh + - name: Unlock git-crypt + run: ./go git_crypt:unlock_with_encrypted_gpg_key + env: + ENCRYPTION_PASSPHRASE: ${{ secrets.ENCRYPTION_PASSPHRASE }} + - name: Configure RubyGems credentials + run: ./scripts/ci/common/configure-rubygems.sh + - name: Set CI git author + run: ./go repository:set_ci_author + - name: Bump version + run: ./go "version:bump[pre]" + - name: Release + run: ./go release + - name: Push commits + run: git push + - name: Push tags + run: git push --tags + - name: Notify Slack of release hold + continue-on-error: true + run: ./go "slack:notify[success,on_hold]" + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + - name: Notify Slack + if: ${{ !cancelled() }} + continue-on-error: true + run: ./go "slack:notify[${{ job.status }}]" + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + + release: + needs: [prerelease] + runs-on: ubuntu-latest + timeout-minutes: 30 + environment: release + concurrency: + group: main + cancel-in-progress: false + queue: max + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + ref: main + - name: Pull latest main + # Publishes main as of approval time, not the SHA that triggered the + # run; --ff-only so a non-fast-forward fails loudly + run: git pull --ff-only + - name: Install tools + uses: infrablocks/github-actions/asdf_install@v1 + - name: Install secrets tools + run: ./scripts/ci/common/install-git-crypt.sh + - name: Unlock git-crypt + run: ./go git_crypt:unlock_with_encrypted_gpg_key + env: + ENCRYPTION_PASSPHRASE: ${{ secrets.ENCRYPTION_PASSPHRASE }} + - name: Configure RubyGems credentials + run: ./scripts/ci/common/configure-rubygems.sh + - name: Set CI git author + run: ./go repository:set_ci_author + - name: Bump version + run: ./go "version:bump[minor]" + - name: Release + run: ./go release + - name: Push commits + run: git push + - name: Push tags + run: git push --tags + - name: Notify Slack + if: ${{ !cancelled() }} + continue-on-error: true + run: ./go "slack:notify[${{ job.status }}]" + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 0000000..8f09f71 --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,115 @@ +name: Pull Request +on: + pull_request: + +permissions: + contents: read + +jobs: + check: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - name: Install tools + uses: infrablocks/github-actions/asdf_install@v1 + - name: Check + run: ./go library:check + - name: Notify Slack + if: ${{ !cancelled() }} + continue-on-error: true + run: ./go "slack:notify[${{ job.status }}]" + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + + test: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - name: Install tools + uses: infrablocks/github-actions/asdf_install@v1 + - name: Test + run: ./go spec + - name: Notify Slack + if: ${{ !cancelled() }} + continue-on-error: true + run: ./go "slack:notify[${{ job.status }}]" + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + + build: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - name: Install tools + uses: infrablocks/github-actions/asdf_install@v1 + - name: Build + run: ./go library:build + - name: Notify Slack + if: ${{ !cancelled() }} + continue-on-error: true + run: ./go "slack:notify[${{ job.status }}]" + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + + prerelease: + needs: [check, test, build] + runs-on: ubuntu-latest + timeout-minutes: 30 + # Same-repo human PRs only: fork and Dependabot PRs carry no secrets, so + # git-crypt unlock / the RubyGems publish would fail. user.login is the + # immutable PR author, not github.actor. + if: >- + github.event.pull_request.head.repo.full_name == github.repository && + github.event.pull_request.user.login != 'dependabot[bot]' + # Queue per PR rather than cancel a mid-flight publish + concurrency: + group: pr-prerelease-${{ github.event.pull_request.number }} + cancel-in-progress: false + steps: + - uses: actions/checkout@v4 + - name: Install tools + uses: infrablocks/github-actions/asdf_install@v1 + - name: Install secrets tools + run: ./scripts/ci/common/install-git-crypt.sh + - name: Unlock git-crypt + run: ./go git_crypt:unlock_with_encrypted_gpg_key + env: + ENCRYPTION_PASSPHRASE: ${{ secrets.ENCRYPTION_PASSPHRASE }} + - name: Configure RubyGems credentials + run: ./scripts/ci/common/configure-rubygems.sh + - name: Publish prerelease + # Facts via env, never interpolated + run: ./go "prerelease:publish[$PR_NUMBER,$RUN_NUMBER,$RUN_ATTEMPT]" + env: + PR_NUMBER: ${{ github.event.pull_request.number }} + RUN_NUMBER: ${{ github.run_number }} + RUN_ATTEMPT: ${{ github.run_attempt }} + - name: Notify Slack + if: ${{ !cancelled() }} + continue-on-error: true + run: ./go "slack:notify[${{ job.status }}]" + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + + merge-pull-request: + needs: [check, test, build] + runs-on: ubuntu-latest + timeout-minutes: 10 + if: github.event.pull_request.user.login == 'dependabot[bot]' + permissions: + contents: write + pull-requests: write + steps: + - name: Merge pull request + # --match-head-commit fails the merge if a commit landed after checks passed + # [skip ci] stops the merge commit triggering a release build + # PR title via env, never interpolated + run: gh pr merge --merge --match-head-commit "$HEAD_SHA" "$PR_URL" --subject "$PR_TITLE [skip ci]" + env: + PR_URL: ${{ github.event.pull_request.html_url }} + PR_TITLE: ${{ github.event.pull_request.title }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Gemfile b/Gemfile index f75d7d2..05b3e81 100644 --- a/Gemfile +++ b/Gemfile @@ -10,11 +10,11 @@ gem 'bundler' gem 'gem-release' gem 'memfs' gem 'rake' -gem 'rake_circle_ci' gem 'rake_git' gem 'rake_git_crypt' gem 'rake_github' gem 'rake_gpg' +gem 'rake_slack' gem 'rspec' gem 'rubocop' gem 'rubocop-rake' diff --git a/Gemfile.lock b/Gemfile.lock index 5666939..c99d356 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,46 +9,52 @@ PATH GEM remote: https://rubygems.org/ specs: - activesupport (7.2.2.1) + activesupport (8.1.3) base64 - benchmark (>= 0.3) bigdecimal concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) + json logger (>= 1.4.2) minitest (>= 5.1) securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) - addressable (2.8.7) - public_suffix (>= 2.0.2, < 7.0) + uri (>= 0.13.1) + addressable (2.9.0) + public_suffix (>= 2.0.2, < 8.0) ast (2.4.3) - base64 (0.2.0) - benchmark (0.4.0) - bigdecimal (3.1.8) + base64 (0.3.0) + bigdecimal (4.1.2) childprocess (5.0.0) colored2 (3.1.2) - concurrent-ruby (1.3.4) - connection_pool (2.4.1) + concurrent-ruby (1.3.8) + connection_pool (3.0.2) diff-lcs (1.6.2) docile (1.4.0) - drb (2.2.1) - excon (0.111.0) - faraday (2.10.0) - faraday-net_http (>= 2.0, < 3.2) + drb (2.2.3) + excon (1.6.0) logger - faraday-net_http (3.1.1) - net-http + faraday (2.14.3) + faraday-net_http (>= 2.0, < 3.5) + json + logger + faraday-net_http (3.4.4) + net-http (~> 0.5) + ffi (1.17.4) + ffi (1.17.4-arm64-darwin) + ffi (1.17.4-x86_64-darwin) + ffi (1.17.4-x86_64-linux-gnu) gem-release (2.2.4) git (1.19.1) addressable (~> 2.8) rchardet (~> 1.8) hamster (3.0.0) concurrent-ruby (~> 1.0) - i18n (1.14.6) + i18n (1.15.2) concurrent-ruby (~> 1.0) - immutable-struct (2.4.1) + immutable-struct (2.5.0) json (2.12.2) language_server-protocol (3.17.0.5) lino (4.1.0) @@ -56,13 +62,12 @@ GEM hamster (~> 3.0) open4 (~> 1.3) lint_roller (1.1.0) - logger (1.6.2) + logger (1.7.0) memfs (1.0.0) - minitest (5.25.4) - net-http (0.4.1) - uri - octokit (8.1.0) - base64 + minitest (5.27.0) + net-http (0.9.1) + uri (>= 0.11.1) + octokit (10.0.0) faraday (>= 1, < 3) sawyer (~> 0.9) open4 (1.3.4) @@ -71,15 +76,10 @@ GEM ast (~> 2.4.1) racc prism (1.4.0) - public_suffix (6.0.1) + public_suffix (7.0.5) racc (1.8.1) rainbow (3.1.1) - rake (13.3.0) - rake_circle_ci (0.13.0) - colored2 (~> 3.1) - excon (~> 0.72) - rake_factory (~> 0.33) - sshkey (~> 2.0) + rake (13.4.2) rake_factory (0.33.0) activesupport (>= 4) rake (~> 13.0) @@ -87,19 +87,26 @@ GEM colored2 (~> 3.1) git (~> 1.13, >= 1.13.2) rake_factory (~> 0.33) - rake_git_crypt (0.2.0) + rake_git_crypt (0.4.0) colored2 (~> 3.1) + lino (~> 4.1) rake_factory (~> 0.33) ruby_git_crypt (~> 0.1) ruby_gpg2 (~> 0.12) - rake_github (0.15.0) + rake_github (0.17.0) colored2 (~> 3.1) - octokit (>= 4.16, < 9.0) + octokit (>= 7.0, < 11.0) rake_factory (~> 0.33) + rbnacl (~> 7.1) sshkey (~> 2.0) rake_gpg (0.20.0) rake_factory (~> 0.33) ruby_gpg2 (~> 0.12) + rake_slack (0.3.0) + excon (>= 0.72, < 2.0) + rake_factory (~> 0.33) + rbnacl (7.1.2) + ffi (~> 1) rchardet (1.8.0) regexp_parser (2.10.0) rspec (3.13.1) @@ -141,10 +148,10 @@ GEM lino (>= 4.1) ruby_gpg2 (0.12.0) lino (>= 4.1) - sawyer (0.9.2) + sawyer (0.9.3) addressable (>= 2.3.5) faraday (>= 0.17.3, < 3) - securerandom (0.4.0) + securerandom (0.4.1) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) @@ -157,7 +164,7 @@ GEM unicode-display_width (3.1.4) unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) - uri (0.13.2) + uri (1.1.1) PLATFORMS arm64-darwin-21 @@ -174,11 +181,11 @@ DEPENDENCIES gem-release memfs rake - rake_circle_ci rake_git rake_git_crypt rake_github rake_gpg + rake_slack rake_ssh! rspec rubocop diff --git a/README.md b/README.md index d61bdc4..cc8ccda 100644 --- a/README.md +++ b/README.md @@ -34,16 +34,16 @@ release a new version, update the version number in `version.rb`, and then run git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). -### Managing CircleCI keys +### Managing CI keys -To encrypt a GPG key for use by CircleCI: +To encrypt a GPG key for use by CI: ```bash openssl aes-256-cbc \ -e \ -md sha1 \ -in ./config/secrets/ci/gpg.private \ - -out ./.circleci/gpg.private.enc \ + -out ./.github/gpg.private.enc \ -k "" ``` @@ -53,7 +53,7 @@ To check decryption is working correctly: openssl aes-256-cbc \ -d \ -md sha1 \ - -in ./.circleci/gpg.private.enc \ + -in ./.github/gpg.private.enc \ -k "" ``` diff --git a/Rakefile b/Rakefile index b6a6651..feabe2a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,15 +1,13 @@ # frozen_string_literal: true -require 'rake_circle_ci' require 'rake_git' require 'rake_git_crypt' require 'rake_github' require 'rake_gpg' -require 'rake_ssh' +require 'rake_slack' require 'rspec/core/rake_task' require 'rubocop/rake_task' require 'securerandom' -require 'yaml' task default: %i[ library:fix @@ -59,13 +57,6 @@ namespace :encryption do end namespace :keys do - namespace :deploy do - RakeSSH.define_key_tasks( - path: 'config/secrets/ci/', - comment: 'maintainers@infrablocks.io' - ) - end - namespace :gpg do RakeGPG.define_generate_key_task( output_directory: 'config/secrets/ci', @@ -91,7 +82,6 @@ namespace :secrets do desc 'Generate all generatable secrets.' task generate: %w[ encryption:passphrase:generate - keys:deploy:generate keys:gpg:generate ] @@ -115,57 +105,101 @@ namespace :library do desc 'Attempt to automatically fix issues with the library' task fix: [:'rubocop:autocorrect_all'] + + desc 'Build the library' + task :build do + sh 'gem build rake_ssh.gemspec' + end end namespace :test do RSpec::Core::RakeTask.new(:unit) end -RakeCircleCI.define_project_tasks( - namespace: :circle_ci, - project_slug: 'github/infrablocks/rake_ssh' -) do |t| - circle_ci_config = - YAML.load_file('config/secrets/circle_ci/config.yaml') - - t.api_token = circle_ci_config['circle_ci_api_token'] - t.environment_variables = { - ENCRYPTION_PASSPHRASE: - File.read('config/secrets/ci/encryption.passphrase') - .chomp - } - t.checkout_keys = [] - t.ssh_keys = [ - { - hostname: 'github.com', - private_key: File.read('config/secrets/ci/ssh.private') - } - ] +namespace :slack do + RakeSlack.define_notification_tasks do |t| + t.bot_token = ENV.fetch('SLACK_BOT_TOKEN', nil) + t.routing_rules = [ + { when: { type: 'on_hold' }, + channel: 'C038EDCRSQJ', format: :on_hold }, # release + { when: { actor: 'dependabot[bot]', outcome: 'success' }, + channel: 'C03N711HVDG', format: :success }, # builds-dependabot + { when: { actor: 'dependabot[bot]' }, + channel: 'C03N711HVDG', format: :failure }, # builds-dependabot + { when: { outcome: 'success' }, + channel: 'C023XUE76GH', format: :success }, # builds + # Failures go to builds, not team-dev (org default), to keep noise + # out of a popular channel while this pipeline beds in. + { when: {}, + channel: 'C023XUE76GH', format: :failure } # builds + ] + end +end + +namespace :repository do + desc 'Set the git author for CI' + task :set_ci_author do + sh 'git config --global user.name "InfraBlocks CI"' + sh 'git config --global user.email "ci@infrablocks.io"' + end +end + +# Operator's ambient auth. Resolve once and fail fast: a missing, +# unauthenticated, or absent gh yields an empty string, which would +# otherwise surface later as an opaque Octokit 401. An empty or +# whitespace-only GITHUB_TOKEN is treated as absent so an authenticated +# operator falls through to `gh auth token` rather than hitting the raise. +def resolve_github_token + token = ENV['GITHUB_TOKEN'].to_s.strip + if token.empty? + token = begin + `gh auth token` + rescue Errno::ENOENT + '' + end.strip + end + return token unless token.empty? + + raise 'No GitHub token available: set GITHUB_TOKEN or run `gh auth login`' +end + +# Actions store only: dependabot runs never reach the passphrase — the +# only pr.yaml job that unlocks git-crypt (prerelease) is guarded to +# same-repo human PRs. Guard against a locked clone: without it, File.read +# returns git-crypt ciphertext and github:secrets:ensure silently uploads +# garbage that only surfaces much later as an opaque GPG unlock failure in +# the release job. +def read_encryption_passphrase + path = 'config/secrets/ci/encryption.passphrase' + raise "Passphrase file not found: #{path} — expected an unlocked clone" \ + unless File.exist?(path) + + passphrase = File.binread(path) + raise 'encryption.passphrase is git-crypt ciphertext — unlock the clone' \ + if passphrase.start_with?("\x00GITCRYPT") + + passphrase.chomp end RakeGithub.define_repository_tasks( namespace: :github, repository: 'infrablocks/rake_ssh' ) do |t| - github_config = - YAML.load_file('config/secrets/github/config.yaml') - - t.access_token = github_config['github_personal_access_token'] - t.deploy_keys = [ - { - title: 'CircleCI', - public_key: File.read('config/secrets/ci/ssh.public') - } + t.access_token = resolve_github_token + t.secrets = [ + { name: 'ENCRYPTION_PASSPHRASE', value: read_encryption_passphrase } + ] + t.environments = [ + { name: 'release', + reviewers: [{ team: 'maintainers' }] } ] end namespace :pipeline do - desc 'Prepare CircleCI Pipeline' + desc 'Prepare GitHub Actions pipeline' task prepare: %i[ - circle_ci:env_vars:ensure - circle_ci:checkout_keys:ensure - circle_ci:ssh_keys:ensure - github:deploy_keys:ensure + github:secrets:ensure + github:environments:ensure ] end @@ -176,6 +210,38 @@ namespace :version do end end +namespace :prerelease do + desc 'Build and push a namespaced pre-release to RubyGems ' \ + '(PR CI only; no bump, no tag, no commit, no push)' + task :publish, %i[pr_number run_number run_attempt] do |_, args| + %i[pr_number run_number run_attempt].each do |name| + raise "Missing task argument: #{name}" if args[name].to_s.empty? + end + + version_file = 'lib/rake_ssh/version.rb' + version_pattern = /(VERSION\s*=\s*')([^']+)(')/ + source = File.read(version_file) + base = source[version_pattern, 2] + raise "Could not read VERSION from #{version_file}" unless base + + version = "#{base}.pr#{args.pr_number}" \ + ".#{args.run_number}.#{args.run_attempt}" + gem_file = "rake_ssh-#{version}.gem" + begin + File.write(version_file, + source.sub(version_pattern, "\\1#{version}\\3")) + # Build + push directly: `gem release` aborts on the (deliberately) + # uncommitted version rewrite. PR CI must not tag, commit, or push + # (contrast the `release` task). + sh 'gem build rake_ssh.gemspec' + sh "gem push #{gem_file}" + ensure + File.write(version_file, source) + rm_f gem_file + end + end +end + desc 'Release gem' task :release do sh 'gem release --tag --push' diff --git a/config/secrets/ci/ssh.private b/config/secrets/ci/ssh.private deleted file mode 100644 index 2fdb650a74e4352fbc0a99b4000536031883ca10..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3265 zcmV;y3_kM!M@dveQdv+`0A(m~i}C*c3#bq&30v8#c0kv^qTzD=j(sb92v5gKVjGX< zWk7@9OuSX>egT2eTrE07KC)9vbqE{{k@0By7|{3}VO1>A8CRe@9GM^zxC%J*mhEC@ zCpd#IY_hQ5+wN0>DdLzk?=5n)KyeU%W1lSEi<;D?nvkmeXxR|)VU9kfU z5|A=A&hHV!6P29*fIe(Rq3n!Pf8i(VNKB(8w?k5dhVDsa{Hbja1mLbDS4CD~$IDJX z<$%_531;d20iTO3C$tS7HmnW?$jzVJ{$UqVMH|vGW?lFi9>YL^-D@8i_8V7W7_+1y zY;wOD31Q)YN}kZoBN-4b+gE|d=HnW;V?8w;bij3pkm=+NN9C1Ar62LQerhRvK=M9X1{hQr)Bn?Gta6X}<6LIor7~1Hbl1dFdw^%h*GCW){ zq@pmq$gN8PwVQHNPtz(kBg04Y+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+kjWfdzr4LGl zk$aqmE`$Ag>(9A+eD^00rW6FjIzp!usEN~eAI?MP-{-Z=i`&55Pq{Pn0_F%ak> zw@7h@Hd6Ut=^j^-6s918d6xj1UeUmYv+G6x>*LH@f5xVUHSkgX=PUTz3{|*yQR(g99TCJq$CYKxmVgN8YU`9z zlm}6k0$yn#7*J7Jr%PWMH|iTb2)PUePSrlNW%6dw3|cFJVmVgAWX8ID=War2u0+#2 z{IX031h2anKOS;-d%JTIT=}V;SmIyjbV~W%0Vp}{q_ifN*Lo0Tf4_T#`k(zLC5KHR Dj5vF4 diff --git a/config/secrets/circle_ci/config.yaml b/config/secrets/circle_ci/config.yaml deleted file mode 100644 index a4d8ce49f0befa3031a15f5b44e2d7c82831bb65..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 120 zcmV-;0EhnoM@dveQdv+`05K+}BElyNml&uGOe?@OrUUoP7Q~t`2o05Ao0DgWk%o&$(AdZ{K`D-uiKgQO^~k5x!(c2sVmb)ZcRalH%_e9*~a{n<2a G8UV%LJx2Nf diff --git a/scripts/ci/common/configure-asdf.sh b/scripts/ci/common/configure-asdf.sh deleted file mode 100755 index b71847a..0000000 --- a/scripts/ci/common/configure-asdf.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -[ -n "$DEBUG" ] && set -x -set -e -set -o pipefail - -function ensure-asdf-plugin() { - local name="$1" - local repo="$2" - - if ! asdf plugin list | grep -q "$name"; then - asdf plugin add "$name" "$repo" - fi -} - -ensure-asdf-plugin "ruby" "https://github.com/asdf-vm/asdf-ruby.git" -ensure-asdf-plugin "java" "https://github.com/halcyon/asdf-java.git" -ensure-asdf-plugin "golang" "https://github.com/asdf-community/asdf-golang.git" diff --git a/scripts/ci/common/configure-git.sh b/scripts/ci/common/configure-git.sh deleted file mode 100755 index cb11b10..0000000 --- a/scripts/ci/common/configure-git.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -[ -n "$DEBUG" ] && set -x -set -e -set -o pipefail - -git config --global user.email "circleci@infrablocks.io" -git config --global user.name "Circle CI" diff --git a/scripts/ci/common/configure-rubygems.sh b/scripts/ci/common/configure-rubygems.sh index 53ba65a..079e256 100755 --- a/scripts/ci/common/configure-rubygems.sh +++ b/scripts/ci/common/configure-rubygems.sh @@ -9,8 +9,6 @@ PROJECT_DIR="$( cd "$SCRIPT_DIR/../../.." && pwd )" cd "$PROJECT_DIR" -git crypt unlock - mkdir -p ~/.gem cp config/secrets/rubygems/credentials ~/.gem/credentials chmod 0600 ~/.gem/credentials diff --git a/scripts/ci/common/install-asdf-dependencies.sh b/scripts/ci/common/install-asdf-dependencies.sh deleted file mode 100755 index cb01457..0000000 --- a/scripts/ci/common/install-asdf-dependencies.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -[ -n "$DEBUG" ] && set -x -set -e -set -o pipefail - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_DIR="$( cd "$SCRIPT_DIR/../../.." && pwd )" - -cd "$PROJECT_DIR" - -asdf install diff --git a/scripts/ci/common/install-asdf.sh b/scripts/ci/common/install-asdf.sh deleted file mode 100755 index 8c1ce8b..0000000 --- a/scripts/ci/common/install-asdf.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -[ -n "$DEBUG" ] && set -x -set -e -set -o pipefail - -apt-get update -apt-get install -y --no-install-recommends \ - ca-certificates \ - curl \ - git - -if [ ! -f "$HOME/.asdf/asdf.sh" ]; then - echo "Installing asdf..." - git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.12.0 -fi - -# shellcheck disable=SC2016 -echo '. "$HOME/.asdf/asdf.sh"' >> "$BASH_ENV" diff --git a/scripts/ci/common/install-git-crypt.sh b/scripts/ci/common/install-git-crypt.sh index 236276d..4de784c 100755 --- a/scripts/ci/common/install-git-crypt.sh +++ b/scripts/ci/common/install-git-crypt.sh @@ -4,5 +4,5 @@ set -e set -o pipefail -apt-get update -apt-get install -y --no-install-recommends git ssh git-crypt +sudo apt-get update +sudo apt-get install -y --no-install-recommends git-crypt gnupg diff --git a/scripts/ci/common/install-gpg-key.sh b/scripts/ci/common/install-gpg-key.sh deleted file mode 100755 index 52d10c2..0000000 --- a/scripts/ci/common/install-gpg-key.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -[ -n "$DEBUG" ] && set -x -set -e -set -o pipefail - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_DIR="$( cd "$SCRIPT_DIR/../../.." && pwd )" - -cd "$PROJECT_DIR" - -set +e -openssl version -openssl aes-256-cbc \ - -d \ - -md sha1 \ - -in ./.circleci/gpg.private.enc \ - -k "${ENCRYPTION_PASSPHRASE}" | gpg --import - -set -e diff --git a/scripts/ci/common/install-slack-deps.sh b/scripts/ci/common/install-slack-deps.sh deleted file mode 100755 index 70abb6b..0000000 --- a/scripts/ci/common/install-slack-deps.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -[ -n "$DEBUG" ] && set -x -set -e -set -o pipefail - -apt-get update -apt-get install -y --no-install-recommends curl jq diff --git a/scripts/ci/steps/build.sh b/scripts/ci/steps/build.sh deleted file mode 100755 index d89621c..0000000 --- a/scripts/ci/steps/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -[ -n "$DEBUG" ] && set -x -set -e -set -o pipefail - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_DIR="$( cd "$SCRIPT_DIR/../../.." && pwd )" - -cd "$PROJECT_DIR" - -./go library:check diff --git a/scripts/ci/steps/merge-pull-request.sh b/scripts/ci/steps/merge-pull-request.sh deleted file mode 100755 index 63be3b1..0000000 --- a/scripts/ci/steps/merge-pull-request.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -[ -n "$DEBUG" ] && set -x -set -e -set -o pipefail - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_DIR="$( cd "$SCRIPT_DIR/../../.." && pwd )" - -cd "$PROJECT_DIR" - -git-crypt unlock - -CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) - -./go github:pull_requests:merge["$CURRENT_BRANCH","%s [skip ci]"] diff --git a/scripts/ci/steps/prerelease.sh b/scripts/ci/steps/prerelease.sh deleted file mode 100755 index c31cf41..0000000 --- a/scripts/ci/steps/prerelease.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -[ -n "$DEBUG" ] && set -x -set -e -set -o pipefail - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_DIR="$( cd "$SCRIPT_DIR/../../.." && pwd )" - -cd "$PROJECT_DIR" - -./go version:bump[pre] -./go release - -git status -git push diff --git a/scripts/ci/steps/release.sh b/scripts/ci/steps/release.sh deleted file mode 100755 index f1f7564..0000000 --- a/scripts/ci/steps/release.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -[ -n "$DEBUG" ] && set -x -set -e -set -o pipefail - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_DIR="$( cd "$SCRIPT_DIR/../../.." && pwd )" - -cd "$PROJECT_DIR" - -git pull - -./go version:bump[minor] -./go release - -git status -git push diff --git a/scripts/ci/steps/test.sh b/scripts/ci/steps/test.sh deleted file mode 100755 index d27b272..0000000 --- a/scripts/ci/steps/test.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -[ -n "$DEBUG" ] && set -x -set -e -set -o pipefail - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_DIR="$( cd "$SCRIPT_DIR/../../.." && pwd )" - -cd "$PROJECT_DIR" - -./go spec From 91898fbeeb6a1c7017bc4eb6cd90f70fa466676c Mon Sep 17 00:00:00 2001 From: Phil Helm Date: Wed, 22 Jul 2026 20:57:25 +0100 Subject: [PATCH 2/2] use test:unit rake task in ci workflows --- .github/workflows/main.yaml | 2 +- .github/workflows/pr.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 31093ce..e1edf84 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -32,7 +32,7 @@ jobs: - name: Install tools uses: infrablocks/github-actions/asdf_install@v1 - name: Test - run: ./go spec + run: ./go test:unit - name: Notify Slack if: ${{ !cancelled() }} continue-on-error: true diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 8f09f71..95916d8 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -30,7 +30,7 @@ jobs: - name: Install tools uses: infrablocks/github-actions/asdf_install@v1 - name: Test - run: ./go spec + run: ./go test:unit - name: Notify Slack if: ${{ !cancelled() }} continue-on-error: true