Skip to content
Closed
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
51 changes: 40 additions & 11 deletions .github/scripts/forge_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,37 @@ def diff(old, new):
return result


# Where a pending Forge update is accepted. Jira's own Manage apps page has no
# Update for it, so it is never named as the place.
ADMIN_PATH = (
"Atlassian Administration (admin.atlassian.com): Apps, Sites, choose the site, "
"Connected apps, Coderhelm, View app details, Update"
)


def admin_steps(install_url=""):
"""The admin's steps, with the installation link first when there is one."""
if install_url:
return (f"An Atlassian site admin opens the app's installation link ({install_url}), "
f"chooses the site and clicks Update, or uses {ADMIN_PATH}.")
return f"An Atlassian site admin accepts the update in {ADMIN_PATH}."


def summary_markdown(result):
"""The run summary text. Holds manifest facts only, never site names."""
lines = ["## Jira app permissions", ""]
if result["needs_admin"]:
lines += [
"**A site admin must accept this update in Jira.** The new version asks for:",
"**An Atlassian site admin must accept this update.** The new version asks for:",
"",
*[f"- {r}" for r in result["reasons"]],
"",
"Forge rolls out code-only changes by itself, but not new access. On each site,",
"an admin opens **Jira settings (gear) → Apps → Manage apps**, finds **Coderhelm**",
"and clicks **Update**. Until then the site keeps running the previous major version.",
admin_steps() + " Until then the site keeps running the previous major version.",
"The workflow also runs `forge install --upgrade` itself; that succeeds only on",
"sites where the Forge token's account is a site admin.",
"sites where the Forge token's account is a site admin. Its refusals elsewhere",
"(\"insufficient permissions\", or a suggestion to install for another product) are",
"about the token's account, not something the site is missing.",
]
else:
lines.append("No new access. Every site gets this version automatically; no one needs to do anything.")
Expand Down Expand Up @@ -242,13 +259,24 @@ def latest_version(versions):
return ".".join(map(str, max(found))) if found else None


def latest_pointer(versions, manifest, commit="", published_at=""):
"""The pointer CoderHelm reads; None when no version is known."""
INSTALL_LINK = re.compile(r"^https://developer\.atlassian\.com/console/install/[^\s]+$")


def latest_pointer(versions, manifest, commit="", published_at="", install_url=""):
"""The pointer CoderHelm reads; None when no version is known.

`install_url` is the app's installation link from the developer console
(Distribution); CoderHelm offers it to site admins as the one-click update.
Anything else is left out.
"""
version = latest_version(versions)
if not version:
return None
app_id = str(((manifest or {}).get("app") or {}).get("id") or "")
return {"version": version, "appId": app_id, "commit": commit, "publishedAt": published_at}
out = {"version": version, "appId": app_id, "commit": commit, "publishedAt": published_at}
if install_url and INSTALL_LINK.match(install_url.strip()):
out["installUrl"] = install_url.strip()
return out


def load_features(path):
Expand Down Expand Up @@ -282,8 +310,8 @@ def behind_report(lines, latest, features):
return "", ""
latest_text = f"latest {latest}" if latest else "latest unknown"
md = ["", "## Sites still behind", ""]
md.append("Each one runs an older Coderhelm app until its Jira admin accepts the update:")
md.append("Jira Settings, Apps, Manage apps, Coderhelm, Update. CoderHelm shows the same on the team's Integrations page.")
md.append("Each one runs an older Coderhelm app until a site admin accepts the update.")
md.append(admin_steps() + " CoderHelm shows the same on the team's Integrations page.")
md.append("")
lacking = []
for i, (major, product) in enumerate(rows, 1):
Expand All @@ -295,7 +323,7 @@ def behind_report(lines, latest, features):
what = f" They lack: {', '.join(lacking)}." if lacking else ""
warning = (
f"{len(rows)} installation(s) still run an older Coderhelm app ({latest_text}).{what}"
" A Jira admin on each site must accept the update: Jira Settings, Apps, Manage apps, Coderhelm, Update."
" " + admin_steps()
)
return "\n".join(md) + "\n", warning

Expand Down Expand Up @@ -327,6 +355,7 @@ def main(argv=None):
la.add_argument("--manifest", required=True)
la.add_argument("--commit", default="")
la.add_argument("--published-at", default="")
la.add_argument("--install-url", default="", help="the app's installation link (developer console, Distribution)")

be = sub.add_parser("behind", help="summary and warning for installations still behind")
be.add_argument("--failed", required=True, help='"major<TAB>product" lines')
Expand Down Expand Up @@ -357,7 +386,7 @@ def main(argv=None):
if args.cmd == "latest":
with open(args.versions, encoding="utf-8") as f:
versions = json.load(f)
pointer = latest_pointer(versions, load_manifest(args.manifest), args.commit, args.published_at)
pointer = latest_pointer(versions, load_manifest(args.manifest), args.commit, args.published_at, args.install_url)
if not pointer:
print("no production version found", file=sys.stderr)
return 1
Expand Down
23 changes: 18 additions & 5 deletions .github/scripts/test_forge_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ def test_widened_scopes_need_admin(self):
self.assertTrue(r["needs_admin"])
self.assertEqual(r["scopes_added"], ["write:jira-work"])
md = fr.summary_markdown(r)
self.assertIn("A site admin must accept", md)
self.assertIn("Apps → Manage apps", md)
self.assertIn("An Atlassian site admin must accept", md)
self.assertIn("Atlassian Administration (admin.atlassian.com): Apps, Sites, choose the site, Connected apps, Coderhelm, View app details, Update", md)
self.assertNotIn("Manage apps", md)
self.assertIn("write:jira-work", md)

def test_removed_scope_still_needs_admin(self):
Expand Down Expand Up @@ -141,7 +142,9 @@ def test_diff_dry_run_writes_summary_and_json(self):
with open(out) as f:
self.assertEqual(json.load(f)["scopes_added"], ["read:me"])
with open(summary) as f:
self.assertIn("Manage apps", f.read())
text = f.read()
self.assertIn("Connected apps", text)
self.assertNotIn("Manage apps", text)

def test_summary_from_saved_result(self):
with tempfile.TemporaryDirectory() as d:
Expand All @@ -151,7 +154,7 @@ def test_summary_from_saved_result(self):
with open(out, "w") as f:
json.dump(r, f)
text = self.run_cli("summary", "--json", out)
self.assertIn("A site admin must accept", text)
self.assertIn("An Atlassian site admin must accept", text)
self.assertNotIn("no one needs to do anything", text)

def test_diff_missing_old_file(self):
Expand All @@ -170,6 +173,15 @@ def test_pending_lists_only_behind_production_installs(self):
self.assertEqual(self.run_cli("pending", "--installs", path), "a.example.net\tjira\t5\n")
self.assertEqual(self.run_cli("pending", "--installs", path, "--environment", "staging"), "c.example.net\tjira\t1\n")

def test_the_installation_link_rides_on_the_pointer_and_the_steps(self):
link = "https://developer.atlassian.com/console/install/00000000-0000-0000-0000-000000000002?signature=abc&product=jira"
p = fr.latest_pointer([{"version": "7.0.0"}], {"app": {"id": "ari:x"}}, install_url=link)
self.assertEqual(p["installUrl"], link)
self.assertNotIn("installUrl", fr.latest_pointer([{"version": "7.0.0"}], {}, install_url="https://example.com/x"))
self.assertIn(link, fr.admin_steps(link))
self.assertIn("Connected apps", fr.admin_steps(link))
self.assertNotIn("Manage apps", fr.admin_steps() + fr.admin_steps(link))

def test_latest_pointer_is_the_highest_production_version(self):
versions = [{"version": "5.20.0"}, {"version": "6.11.0"}, {"version": "6.9.0"}, {"version": "soon"}]
manifest = {"app": {"id": "ari:cloud:ecosystem::app/00000000-0000-0000-0000-000000000001"}}
Expand Down Expand Up @@ -197,7 +209,8 @@ def test_behind_lists_each_site_by_number_with_what_it_lacks(self):
self.assertIn("threaded replies", md)
self.assertNotIn("example", md)
self.assertTrue(warning.startswith("2 installation(s) still run an older Coderhelm app (latest 6.11.0). They lack: "))
self.assertIn("Jira Settings, Apps, Manage apps, Coderhelm, Update.", warning)
self.assertIn("Connected apps, Coderhelm, View app details, Update.", warning)
self.assertNotIn("Manage apps", warning + md)
self.assertEqual(fr.behind_report([], "6.11.0", features), ("", ""))
self.assertEqual(fr.parse_version("6.10"), (6, 10, 0))
self.assertIsNone(fr.parse_version("6.x"))
Expand Down
20 changes: 16 additions & 4 deletions .github/workflows/jira-app-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,16 @@ jobs:
# numbers each deploy, so the version is read back from Forge.
- name: Read the released version
id: version
env:
# The app's installation link (developer console, Distribution),
# kept as a repository variable: site admins get it as the
# one-click update.
FORGE_INSTALL_URL: ${{ vars.FORGE_INSTALL_URL }}
run: |
if forge version list --environment production --non-interactive --json > "$RUNNER_TEMP/versions.json" 2> "$RUNNER_TEMP/versions.err" \
&& python3 "$RUNNER_TEMP/forge_release.py" latest --versions "$RUNNER_TEMP/versions.json" --manifest manifest.yml \
--commit "$(git rev-parse HEAD)" --published-at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" > "$RUNNER_TEMP/jira-app.json"; then
--commit "$(git rev-parse HEAD)" --published-at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
--install-url "${FORGE_INSTALL_URL}" > "$RUNNER_TEMP/jira-app.json"; then
version=$(python3 -c 'import json,sys;print(json.load(open(sys.argv[1]))["version"])' "$RUNNER_TEMP/jira-app.json")
echo "Released version: $version"
echo "version=$version" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -221,7 +227,7 @@ jobs:
# Minor versions reach every site by themselves. Installations still
# on an older major version are upgraded here; that works on sites
# where the token's account is a site admin, and elsewhere waits for
# that site's admin to accept the update in Jira.
# that site's admin to accept the update in Atlassian Administration.
forge install list --json > "$RUNNER_TEMP/installs.json" 2> "$RUNNER_TEMP/installs.err" || {
echo "::warning::Could not list installations"; echo "listed=false" >> "$GITHUB_OUTPUT"; exit 0; }
python3 "$RUNNER_TEMP/forge_release.py" pending --installs "$RUNNER_TEMP/installs.json" > "$RUNNER_TEMP/pending.tsv"
Expand All @@ -234,10 +240,15 @@ jobs:
while IFS=$'\t' read -r site product major; do
[ -n "$site" ] || continue
echo "::add-mask::$site"
# The CLI's own refusal (insufficient permissions, or advice to
# install for another product) is about the token's account, not
# the site: it stays in the log, quietly, and the summary says
# what the site's admin does.
if forge install --upgrade --site "$site" --product "$product" \
--environment production --non-interactive --confirm-scopes; then
--environment production --non-interactive --confirm-scopes > "$RUNNER_TEMP/upgrade.log" 2>&1; then
upgraded=$((upgraded + 1))
else
echo "Not upgraded from CI (the Forge token's account isn't an admin on this site); its admin accepts the update."
failed=$((failed + 1))
printf '%s\t%s\n' "$major" "$product" >> "$RUNNER_TEMP/behind.tsv"
fi
Expand Down Expand Up @@ -269,6 +280,7 @@ jobs:
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
FAILED: ${{ steps.upgrade.outputs.failed || '0' }}
BEHIND: ${{ steps.upgrade.outputs.warning }}
FORGE_INSTALL_URL: ${{ vars.FORGE_INSTALL_URL }}
run: |
# The issue holds counts and manifest facts only, never site names.
title="Jira app update needs a site admin"
Expand All @@ -278,7 +290,7 @@ jobs:
"$reasons" \
"Installations not upgraded from CI: ${FAILED}." \
"${BEHIND}" \
"On each site, a Jira admin accepts the update: Jira Settings, Apps, Manage apps, Coderhelm, Update." \
"$(python3 -c 'import sys;sys.path.insert(0,sys.argv[1]);import forge_release as f;print(f.admin_steps(sys.argv[2]))' "$RUNNER_TEMP" "${FORGE_INSTALL_URL}")" \
"Run: ${RUN_URL}")
existing=$(gh issue list --repo "$GITHUB_REPOSITORY" --state open --search "in:title \"$title\"" --json number --jq '.[0].number // empty')
if [ -n "$existing" ]; then
Expand Down
11 changes: 0 additions & 11 deletions coderhelm-jira/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ modules:
function: addCommentHandler
- key: get-site-url-trigger
function: getSiteUrlHandler
- key: publish-release-trigger
function: publishReleaseHandler
- key: get-issues-trigger
function: getIssuesHandler
- key: confluence-trigger
function: confluenceHandler
jira:adminPage:
- key: coderhelm-admin-page
resource: adminPage
Expand All @@ -46,12 +42,8 @@ modules:
handler: index.addCommentHandler
- key: getSiteUrlHandler
handler: index.getSiteUrlHandler
- key: publishReleaseHandler
handler: release.publishReleaseHandler
- key: getIssuesHandler
handler: release.getIssuesHandler
- key: confluenceHandler
handler: confluence.confluenceHandler
- key: lifecycleHandler
handler: register.lifecycleHandler
resources:
Expand All @@ -63,9 +55,6 @@ permissions:
- write:jira-work
- storage:app
- read:attachment:jira
- read:page:confluence
- read:space:confluence
- write:page:confluence
external:
fetch:
backend:
Expand Down
72 changes: 0 additions & 72 deletions coderhelm-jira/src/confluence-rules.js

This file was deleted.

Loading
Loading