Skip to content

Commit cd2ca40

Browse files
Add Sonatype Guide workflow file (#3)
Co-authored-by: sonatype-guide[bot] <262430933+sonatype-guide[bot]@users.noreply.github.com>
1 parent 53437c5 commit cd2ca40

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

.github/workflows/agp-workflow.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#
2+
# Sonatype Guide — Agent P (AGP) Workflow
3+
# Learn more: https://guide.sonatype.com
4+
#
5+
# File: .github/workflows/agp-workflow.yml
6+
#
7+
# Authentication: Uses GitHub OIDC (id-token: write) to authenticate with
8+
# Sonatype Guide.
9+
#
10+
# How this works:
11+
# 1. The lightweight `gate` job calls Sonatype Guide over OIDC to fetch your
12+
# organization's governed configuration and a run/pause directive. It runs no
13+
# container, so it is fast and cheap.
14+
# 2. The `agp` job only runs when the gate says `run`. If your repository is paused
15+
# in Guide — or Guide is unreachable — the `agp` job is skipped entirely, so no
16+
# runner is allocated and no container image is pulled.
17+
#
18+
# Configuration is governed centrally in Sonatype Guide; there is no agp.yml to edit
19+
# in this repository — the gate writes the effective configuration at run time.
20+
#
21+
# Optional:
22+
# - set variable AGP_API_URL to a specific Sonatype Guide Environment, if not provided
23+
# defaults to the Production AGP API URL.
24+
25+
name: Sonatype Guide - Agent P
26+
27+
on:
28+
schedule:
29+
# Runs once a day. Change it to any schedule preferred.
30+
- cron: '16 21 * * *'
31+
workflow_dispatch:
32+
inputs:
33+
verbose:
34+
description: 'Enable verbose output'
35+
required: false
36+
default: 'false'
37+
type: boolean
38+
# Declared so Sonatype Guide can start this workflow via the dispatch API: GitHub rejects a
39+
# workflow_dispatch carrying inputs the workflow does not declare. Full runs send mode;
40+
# targeted security-fix runs also send vulnerabilities; heal runs also send repo_id.
41+
mode:
42+
description: 'Run mode (full, security, or heal)'
43+
required: false
44+
default: 'full'
45+
type: string
46+
repo_id:
47+
description: 'Sonatype Guide repository id (required for heal mode)'
48+
required: false
49+
type: number
50+
vulnerabilities:
51+
description: 'JSON array of vulnerabilities to target (security mode)'
52+
required: false
53+
default: ''
54+
type: string
55+
56+
permissions:
57+
contents: write
58+
pull-requests: write
59+
id-token: write # Required for Sonatype Guide OIDC authentication
60+
61+
concurrency:
62+
group: agp-workflow
63+
cancel-in-progress: false
64+
65+
jobs:
66+
# Cheap, Docker-free gate. Determines whether AGP should run for this repo and, when
67+
# it should, writes the governed effective agp.yml to the workspace (fail-closed).
68+
gate:
69+
runs-on: ubuntu-latest
70+
timeout-minutes: 5
71+
outputs:
72+
directive: ${{ steps.gate.outputs.directive }}
73+
steps:
74+
- name: Checkout
75+
uses: actions/checkout@v5
76+
- name: Sonatype Guide gate
77+
id: gate
78+
uses: sonatype/agp-action/gate@v1
79+
with:
80+
guide-url: ${{ vars.AGP_API_URL }}
81+
82+
agp:
83+
needs: gate
84+
if: needs.gate.outputs.directive == 'run'
85+
runs-on: ubuntu-latest
86+
timeout-minutes: 60
87+
steps:
88+
- name: Checkout
89+
uses: actions/checkout@v5
90+
91+
- name: Fetch governed configuration
92+
# GitHub jobs run separately and don't share files, so fetch the governed configuration
93+
# again here for the AGP run below to use.
94+
uses: sonatype/agp-action/gate@v1
95+
with:
96+
guide-url: ${{ vars.AGP_API_URL }}
97+
98+
- name: Run AGP
99+
uses: sonatype/agp-action@v1
100+
with:
101+
# Forward the dispatch inputs so a backend-triggered run targets the right mode.
102+
# A full/scheduled run sends mode=full; security-fix sends mode=security
103+
# with a vulnerabilities payload; heal sends mode=heal with repo_id.
104+
mode: ${{ inputs.mode || 'full' }}
105+
repo_id: ${{ inputs.repo_id || '' }}
106+
vulnerabilities: ${{ inputs.vulnerabilities }}
107+
verbose: ${{ inputs.verbose || 'false' }}
108+
env:
109+
AGP_API_URL: ${{ vars.AGP_API_URL }}

0 commit comments

Comments
 (0)