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
10 changes: 10 additions & 0 deletions .github/workflows/_generate-rebase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ on:
secrets:
REPO_ACCESS_TOKEN:
required: true
description: Token with contents and pull-request write access

permissions:
contents: read

jobs:
rebase:
runs-on: ubuntu-latest
timeout-minutes: 35
steps:

- name: Check out repository
Expand All @@ -42,6 +44,14 @@ jobs:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
ref: ${{ github.ref_name }}

- name: Trigger and wait for OCA if required
run: bash scripts/release_scripts/wait_for_oca.sh
env:
GH_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
GH_REPO: ${{ github.repository }}
TO_HEAD: ${{ inputs.to_head }}
FROM_BASE: ${{ inputs.from_base }}

- name: Do rebase
run: |
git config --global user.name "$USER_NAME"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macaron-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# Note: adjust the policy_purl to refer to your repository URL.
- name: Run Macaron action
id: run_macaron
uses: oracle/macaron@794eec32782979f577efb5ff71d585f683a3550f # v0.25.0
uses: oracle/macaron@5d8f162a5d33f91a7048e861f1ff946a9791fe64 # v0.26.0
with:
repo_path: ./
policy_file: check-github-actions
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Use Macaron as a GitHub Action
To use the Macaron GitHub Action, add the following step to your workflow (adjust the version as needed). In this example, we use an example policy. For detailed instructions and a comprehensive list of available options, please refer to the [Macaron GitHub Action documentation](https://oracle.github.io/macaron/pages/macaron_action.html).

```yaml
- uses: oracle/macaron@794eec32782979f577efb5ff71d585f683a3550f # v0.25.0
- uses: oracle/macaron@5d8f162a5d33f91a7048e861f1ff946a9791fe64 # v0.26.0
with:
repo_path: ./
policy_file: check-github-actions
Expand Down
4 changes: 2 additions & 2 deletions docs/source/pages/macaron_action.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ When you use this action, you can reference it directly in your workflow. For a
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Run Macaron Security Analysis Action
uses: oracle/macaron@794eec32782979f577efb5ff71d585f683a3550f # v0.25.0
uses: oracle/macaron@5d8f162a5d33f91a7048e861f1ff946a9791fe64 # v0.26.0
with:
repo_path: ./
policy_file: check-github-actions
Expand All @@ -45,7 +45,7 @@ verification reads the matching ``macaron.db``.
.. code-block:: yaml

- name: Verify policy
uses: oracle/macaron@794eec32782979f577efb5ff71d585f683a3550f # v0.25.0
uses: oracle/macaron@5d8f162a5d33f91a7048e861f1ff946a9791fe64 # v0.26.0
with:
policy_file: policy.dl

Expand Down
45 changes: 45 additions & 0 deletions scripts/release_scripts/wait_for_oca.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# Copyright (c) 2026 - 2026, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.

set -euo pipefail

# Skip the PR workaround when the organization no longer requires OCA.
encoded_branch=$(jq -rn --arg branch "$TO_HEAD" '$branch | @uri')
rules=$(gh api "repos/$GH_REPO/rules/branches/$encoded_branch")
oca_required=$(jq -r 'any(.[] | select(.type == "required_status_checks")
| .parameters.required_status_checks[]; .context == "oca/oracle")' <<< "$rules")
if [[ "$oca_required" == "false" ]]; then
echo "OCA is not required; continuing with the rebase."
exit 0
fi

source_branch=${FROM_BASE#origin/}
pr_url=$(gh pr list --repo "$GH_REPO" --base "$TO_HEAD" --head "$source_branch" \
--state open --json url --jq '.[0].url // empty')
if [[ -z "$pr_url" ]]; then
pr_url=$(gh pr create --repo "$GH_REPO" --base "$TO_HEAD" --head "$source_branch" \
--title "chore: synchronize $TO_HEAD after release" \
--body "Trigger OCA verification before the release workflow rebases $TO_HEAD onto $source_branch. No manual merge is needed.")
fi
head_sha=$(gh pr view "$pr_url" --repo "$GH_REPO" --json headRefOid --jq '.headRefOid')
echo "Waiting for OCA: $pr_url"
deadline=$((SECONDS + ${OCA_CHECK_TIMEOUT_SECONDS:-1800}))
while true; do
response=$(gh api "repos/$GH_REPO/commits/$head_sha/check-runs?check_name=oca%2Foracle&filter=latest&per_page=100")
state=$(jq -er '
[.check_runs[] | select(.name == "oca/oracle" and .app.slug == "oracle-contributor-agreement")]
| max_by(.id)
| if . == null or .status != "completed" then "pending" else .conclusion end
' <<< "$response")
case "$state" in
success) exit 0 ;;
pending) ;;
*) echo "OCA did not pass. Inspect $pr_url." >&2; exit 1 ;;
esac
if (( SECONDS >= deadline )); then
echo "Timed out waiting for OCA. Inspect $pr_url." >&2
exit 1
fi
sleep "${OCA_CHECK_INTERVAL_SECONDS:-15}"
done
93 changes: 93 additions & 0 deletions tests/release_scripts/test_wait_for_oca.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright (c) 2026 - 2026, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.

"""Test the optional OCA gate without making GitHub requests."""

# The subprocess runs a repository script with a controlled GitHub CLI.
# ruff: noqa: S603, S607

import os
import subprocess
import sys
from pathlib import Path

import pytest


@pytest.mark.parametrize(
"mode",
["not_required", "success", "pending", "existing_pr", "failure", "cancelled", "missing", "api_error"],
)
def test_wait_for_oca(tmp_path: Path, mode: str) -> None:
"""Skip an obsolete requirement, wait for a pending check, and stop on failure."""
cli = tmp_path / "gh"
cli.write_text(
f"#!{sys.executable}\n"
+ r"""
import json
import os
import sys
from pathlib import Path

args = sys.argv[1:]
mode = os.environ["OCA_TEST_MODE"]
root = Path(os.environ["OCA_TEST_ROOT"])
with (root / "requests").open("a") as log:
log.write(json.dumps(args) + "\n")
if mode == "api_error":
sys.exit("GitHub API unavailable")
if args[0] == "api" and "/rules/branches/" in args[1]:
print(json.dumps([] if mode == "not_required" else [{
"type": "required_status_checks",
"parameters": {"required_status_checks": [{"context": "oca/oracle"}]},
}]))
elif args[:2] == ["pr", "list"]:
print("https://github.com/example/project/pull/7" if mode == "existing_pr" else "")
elif args[:2] == ["pr", "create"]:
if mode == "existing_pr":
sys.exit("Existing PR must be reused")
print("https://github.com/example/project/pull/7")
elif args[:2] == ["pr", "view"]:
print("a" * 40)
elif args[0] == "api" and "/commits/" + "a" * 40 + "/check-runs?check_name=oca%2Foracle" in args[1]:
polled = root / "polled"
pending = mode == "pending" and not polled.exists()
polled.touch()
print(json.dumps({"check_runs": [] if mode == "missing" else [{
"id": 1,
"name": "oca/oracle",
"app": {"slug": "oracle-contributor-agreement"},
"status": "in_progress" if pending else "completed",
"conclusion": mode if mode in {"failure", "cancelled"} else "success",
}]}))
else:
sys.exit(f"Unexpected request: {args}")
""",
encoding="utf-8",
)
cli.chmod(0o755)
script = Path(__file__).resolve().parents[2] / "scripts/release_scripts/wait_for_oca.sh"
result = subprocess.run(
["bash", str(script)],
env={
**os.environ,
"PATH": str(tmp_path) + os.pathsep + os.environ["PATH"],
"GH_REPO": "example/project",
"GH_TOKEN": "test-token",
"TO_HEAD": "main",
"FROM_BASE": "origin/release",
"OCA_TEST_MODE": mode,
"OCA_TEST_ROOT": str(tmp_path),
"OCA_CHECK_TIMEOUT_SECONDS": "1",
"OCA_CHECK_INTERVAL_SECONDS": "0",
},
capture_output=True,
text=True,
check=False,
)
assert (result.returncode == 0) is (mode in {"not_required", "success", "pending", "existing_pr"}), result.stderr
requests = (tmp_path / "requests").read_text(encoding="utf-8").splitlines()
if mode == "not_required":
assert len(requests) == 1, "No PR should be opened when OCA is no longer required"
if mode == "pending":
assert len([request for request in requests if "check-runs?" in request]) == 2
Loading