Skip to content
Open
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ jobs:

- name: Build ecosystem image
if: steps.changes.outputs[matrix.suite.path] == 'true'
env:
GH_TOKEN: ${{ matrix.suite.path == 'github_actions' && secrets.GITHUB_TOKEN || '' }}
run: script/build ${{ matrix.suite.build || matrix.suite.path }}

- name: Run ${{ matrix.suite.name }} tests
Expand Down
8 changes: 8 additions & 0 deletions github_actions/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ ARG TARGETARCH
ARG GH_ACTIONS_LOCK_VERSION=v0.4.1
ARG GH_ACTIONS_LOCK_AMD64_CHECKSUM=39deb2fe714dbf74b073d8245fc7f3d50cd0eee18d5c0900e9e849ae933ae17e
ARG GH_ACTIONS_LOCK_ARM64_CHECKSUM=aee61c993da36a5f09be2c77e6e4a1a22542a1b30ded4996bf8301c15dcf2b39
ARG GH_AW_VERSION=v1.2.0

# gh aw uses gh to resolve action references that are not in its embedded pin catalog.
USER root
RUN apt-get update \
&& apt-get install -y --no-install-recommends gh \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir -p /opt/github_actions/bin \
&& curl -fsSL -o /opt/github_actions/bin/gh-actions-lock \
"https://github.com/github/gh-actions-lock/releases/download/${GH_ACTIONS_LOCK_VERSION}/linux-${TARGETARCH}" \
Expand All @@ -17,6 +23,8 @@ RUN mkdir -p /opt/github_actions/bin \
&& chmod +x /opt/github_actions/bin/gh-actions-lock

USER dependabot
RUN --mount=type=secret,id=github_token,env=GH_TOKEN,required=true \
gh extension install github/gh-aw --pin "${GH_AW_VERSION}"

COPY --chown=dependabot:dependabot --parents github_actions common $DEPENDABOT_HOME/
COPY --chown=dependabot:dependabot updater $DEPENDABOT_HOME/dependabot-updater
29 changes: 29 additions & 0 deletions github_actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@

GitHub Actions support for [`dependabot-core`][core-repo].

### GitHub Agentic Workflows

For [gh aw](https://github.com/github/gh-aw) workflows, Dependabot updates action
references declared in the YAML frontmatter of the source `.md` files, including
local frontmatter imports. It then recompiles affected `.lock.yml` files rather
than editing generated YAML. The selected workflows are compiled with
`gh aw compile --fix`; any compiler migrations to their Markdown are also
included in the update. Workflows are not refreshed from upstream repositories,
and unrelated action references are not deliberately bumped.
The usual `github-actions` configuration applies; no separate ecosystem is needed.
Compiled workflows are identified by their `.lock.yml` filenames and the JSON
`gh-aw-metadata` or `gh-aw-manifest` comments.

The compiler is installed in the updater image as the `gh-aw` GitHub CLI extension,
pinned through `GH_AW_VERSION`. Local imports, `aw.json`, and the action pin cache
are preserved as compilation inputs; updated lockfiles and cache changes are
included in the dependency update. Compilation failures prevent the update from
being returned.

The GitHub CLI is also used to resolve action references outside the compiler's
embedded pin catalog.

Building the updater image requires `GH_TOKEN` so the GitHub CLI can install the
pinned extension. The build passes it as a BuildKit secret; it is not stored in
the image.

Actions inserted by the compiler are not independently updated by Dependabot.
They may change when recompiling with a newer eligible compiler release.

### Running locally

1. Start a development shell
Expand Down
149 changes: 149 additions & 0 deletions github_actions/lib/dependabot/github_actions/agentic_workflow.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# typed: strict
# frozen_string_literal: true

require "pathname"
require "sorbet-runtime"

require "dependabot/dependency_file"
require "dependabot/errors"
require "dependabot/github_actions/workflow_file"

module Dependabot
module GithubActions
class AgenticWorkflow
extend T::Sig

ACTION_CACHE_PATH = ".github/aw/actions-lock.json"
FRONTMATTER_PATTERN = /\A(?:\uFEFF)?---[ \t]*\r?\n(?<yaml>.*?)^---[ \t]*(?:\r?\n|\z)/m

class Import < T::Struct
const :path, String
const :optional, T::Boolean, default: false
const :frontmatter, T::Boolean, default: true
end

sig { params(file: Dependabot::DependencyFile).returns(T::Boolean) }
def self.generated?(file)
file.name.end_with?(".lock.yml") &&
file.content.to_s.match?(/^# gh-aw-(?:metadata|manifest):/)
end

sig { params(file: Dependabot::DependencyFile).returns(String) }
def self.source_path(file)
file.path.delete_prefix("/").sub(/\.lock\.yml\z/, ".md")
end

sig { params(file: Dependabot::DependencyFile).void }
def initialize(file)
@file = file
@content = T.let(T.must(file.content), String)
@frontmatter_match = T.let(FRONTMATTER_PATTERN.match(@content), T.nilable(MatchData))
end

sig { returns(String) }
def frontmatter
return T.must(@frontmatter_match[:yaml]) if @frontmatter_match
return "" unless @content.match?(/\A(?:\uFEFF)?---[ \t]*\r?\n/)

raise DependencyFileNotParseable.new(@file.path, "Unterminated gh aw YAML frontmatter")
end

sig { returns(WorkflowFile) }
def workflow_file
WorkflowFile.new(frontmatter)
end

sig { params(yaml: String).returns(String) }
def updated_content(yaml)
match = T.must(@frontmatter_match)
T.must(@content[0...match.begin(:yaml)]) + yaml + @content[match.end(:yaml)..].to_s
end

sig { params(workflow_directory: String, include_frontmatter: T::Boolean).returns(T::Array[Import]) }
def imports(workflow_directory:, include_frontmatter: true)
paths = include_frontmatter ? frontmatter_imports : []
paths.map do |path|
target = T.must(path.delete_suffix("?").split("#", 2).first)
Import.new(path: resolve_import(target, workflow_directory), optional: path.end_with?("?"))
end + body_imports(workflow_directory)
rescue Psych::SyntaxError, Psych::DisallowedClass, Psych::BadAlias
raise DependencyFileNotParseable, @file.path
end

private

sig { returns(T::Array[String]) }
def frontmatter_imports
data = workflow_file.data
return [] unless data.is_a?(Hash)

imports = data["imports"]
return [] unless imports.is_a?(Array)

imports.filter_map do |entry|
path = entry.is_a?(Hash) ? entry["uses"] || entry["path"] : entry
path if path.is_a?(String) && local_import?(path)
end
end

sig { params(workflow_directory: String).returns(T::Array[Import]) }
def body_imports(workflow_directory)
imports = T.let([], T::Array[Import])
@content.scan(/\{\{#(?<kind>runtime-import\??|import)\s+(?<path>[^\s}]+)\s*\}\}/) do
match = T.must(Regexp.last_match)
path = T.must(match[:path])
next unless local_import?(path)

runtime = match[:kind] != "import"
imports << Import.new(
path: runtime ? resolve_runtime_import(path, workflow_directory) : resolve_import(path, workflow_directory),
optional: match[:kind] == "runtime-import?",
frontmatter: !runtime
)
end
imports
end

sig { params(path: String).returns(T::Boolean) }
def local_import?(path)
!path.match?(%r{\Ahttps?://}) && !path.include?("@")
end

sig { params(path: String, workflow_directory: String).returns(String) }
def resolve_runtime_import(path, workflow_directory)
if path.start_with?("/")
raise DependencyFileNotResolvable, "gh aw runtime imports cannot use absolute paths: #{path}"
end

target = path.sub(/:\d+(?:-\d+)?\z/, "")
target = ".github/#{target}" unless target.start_with?(".github/", ".agents/")
resolved = resolve_import(target, workflow_directory)
unless resolved.start_with?(".github/", ".agents/")
raise DependencyFileNotResolvable, "gh aw runtime import escapes its source directory: #{path}"
end

resolved
end

sig { params(path: String, workflow_directory: String).returns(String) }
def resolve_import(path, workflow_directory)
base = if path.start_with?("/", ".github/", ".agents/")
""
elsif path.start_with?("./", "../") || !path.include?("/")
File.dirname(@file.path.delete_prefix("/"))
else
workflow_directory
end
resolved = Pathname.new(File.join(base, path.delete_prefix("/")).delete_prefix("/")).cleanpath.to_s
if resolved == ".." || resolved.start_with?("../")
raise DependencyFileNotResolvable, "gh aw import escapes the repository: #{path}"
end
if resolved.split("/").include?(".git")
raise DependencyFileNotResolvable, "gh aw imports cannot read reserved Git metadata: #{path}"
end

resolved
end
end
end
end
72 changes: 72 additions & 0 deletions github_actions/lib/dependabot/github_actions/file_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require "dependabot/file_fetchers/base"
require "dependabot/experiments"
require "dependabot/github_actions/constants"
require "dependabot/github_actions/agentic_workflow"
require "dependabot/github_actions/workflow_file"

module Dependabot
Expand Down Expand Up @@ -48,6 +49,7 @@ def fetch_files
fetched_files += correctly_encoded_workflow_files

if fetched_files.any?
fetched_files += agentic_workflow_files
# The lockfile is additive: it is only fetched alongside workflow files
# and never activates the ecosystem on its own. Relocking also requires
# every workflow to be materialized, so retain the workflow-only path if
Expand Down Expand Up @@ -78,6 +80,76 @@ def fetch_files

private

sig { returns(T::Array[DependencyFile]) }
def agentic_workflow_files
generated = correctly_encoded_workflow_files.select { |file| AgenticWorkflow.generated?(file) }
return [] if generated.empty?

files = T.let({}, T::Hash[String, DependencyFile])
generated.each do |file|
file.support_file = true
source_path = AgenticWorkflow.source_path(file)
markdown = fetch_file_from_host(relative_to_directory(source_path))
fetch_agentic_imports(markdown, File.dirname(source_path), files)
end
config_paths = generated.map do |file|
File.join(File.dirname(file.path.delete_prefix("/")), "aw.json")
end
(config_paths + [AgenticWorkflow::ACTION_CACHE_PATH]).uniq.each do |path|
file = fetch_file_if_present(relative_to_directory(path))
next unless file

file.support_file = true
files[path] = file
end
files.values
end

sig do
params(
file: DependencyFile,
workflow_directory: String,
files: T::Hash[String, DependencyFile],
include_frontmatter: T::Boolean
).void
end
def fetch_agentic_imports(file, workflow_directory, files, include_frontmatter: true)
path = file.path.delete_prefix("/")
existing = files[path]
return if agentic_file_processed?(existing, include_frontmatter)
raise DependencyFileNotParseable, file.path unless file.content&.valid_encoding?

file = existing || file
files[path] = file
file.support_file = true
return unless file.name.end_with?(".md")

file.support_file = !include_frontmatter
AgenticWorkflow.new(file).imports(
workflow_directory: workflow_directory, include_frontmatter: include_frontmatter
).each do |import|
relative_path = relative_to_directory(import.path)
imported = files[import.path] || fetch_agentic_import(import, relative_path)
next unless imported

fetch_agentic_imports(
imported, workflow_directory, files, include_frontmatter: include_frontmatter && import.frontmatter
)
end
end

sig { params(file: T.nilable(DependencyFile), include_frontmatter: T::Boolean).returns(T::Boolean) }
def agentic_file_processed?(file, include_frontmatter)
return false unless file

!include_frontmatter || !file.support_file?
end

sig { params(import: AgenticWorkflow::Import, relative_path: String).returns(T.nilable(DependencyFile)) }
def fetch_agentic_import(import, relative_path)
import.optional ? fetch_file_if_present(relative_path) : fetch_file_from_host(relative_path)
end

# The lockfile plus everything the engine needs to relock it, or nothing when
# a workflow it would read is invalidly encoded.
sig { returns(T::Array[DependencyFile]) }
Expand Down
11 changes: 9 additions & 2 deletions github_actions/lib/dependabot/github_actions/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require "dependabot/file_parsers"
require "dependabot/file_parsers/base"
require "dependabot/github_actions/constants"
require "dependabot/github_actions/agentic_workflow"
require "dependabot/github_actions/lockfile/reader"
require "dependabot/github_actions/version"
require "dependabot/github_actions/package_manager"
Expand Down Expand Up @@ -56,7 +57,11 @@ def package_manager
sig { params(file: Dependabot::DependencyFile).returns(Dependabot::FileParsers::Base::DependencySet) }
def workfile_file_dependencies(file)
dependency_set = DependencySet.new
workflow_file = WorkflowFile.new(T.must(file.content))
workflow_file = if file.name.end_with?(".md")
AgenticWorkflow.new(file).workflow_file
else
WorkflowFile.new(T.must(file.content))
end
workflow_file.uses_declarations.group_by(&:value).each do |string, declarations|
dep = dependency_for_declarations(file, workflow_file, string, declarations)
next unless dep
Expand Down Expand Up @@ -226,7 +231,9 @@ def lockfile_reader

sig { returns(T::Array[Dependabot::DependencyFile]) }
def workflow_files
dependency_files.reject { |file| file.support_file? || file.path.delete_prefix("/") == LOCKFILE_PATH }
dependency_files.reject do |file|
file.support_file? || AgenticWorkflow.generated?(file) || file.path.delete_prefix("/") == LOCKFILE_PATH
end
end

sig { override.void }
Expand Down
Loading
Loading