Skip to content

Commit 4ceae77

Browse files
committed
ci: moon task tweaks to add github pkg publishign to raa
1 parent fdda858 commit 4ceae77

10 files changed

Lines changed: 230 additions & 23 deletions

File tree

.github/actions/moon-raa/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# moon-raa
2+
3+
Manage review apps and artifacts (RAA) for a Moon monorepo. Creates GitHub Deployments, runs per-project build/teardown tasks, and produces a manifest of artifacts.
4+
5+
## Usage
6+
7+
```yaml
8+
- uses: ./.github/actions/moon-raa
9+
with:
10+
command: run # or rm
11+
pr-number: ${{ inputs.pr-number }}
12+
github-token: ${{ secrets.GITHUB_TOKEN }}
13+
```
14+
15+
## Inputs
16+
17+
| Input | Required | Default | Description |
18+
| -------------- | -------- | ------- | --------------------------------------------------------- |
19+
| `command` | yes | | `run` to build review artifacts, `rm` to tear down |
20+
| `pr-number` | yes | | PR number |
21+
| `prefix` | no | `raa` | Environment name prefix (produces `<prefix>-pr-<number>`) |
22+
| `github-token` | yes | | `GITHUB_TOKEN` for deployment API calls |
23+
24+
## Outputs
25+
26+
| Output | Command | Description |
27+
| --------------- | ------- | --------------------------------------------- |
28+
| `deployment-id` | run | GitHub Deployment ID |
29+
| `environment` | both | Environment name (e.g. `raa-pr-42`) |
30+
| `project-count` | both | Number of projects processed |
31+
| `summary` | both | Markdown summary for `GITHUB_STEP_SUMMARY` |
32+
| `manifest` | run | Full payload as JSON |
33+
| `clean` | rm | `true` if teardown completed without warnings |
34+
35+
## Project Configuration
36+
37+
The action discovers affected projects via `moon query projects --affected` and filters to those with `raa` metadata in their `moon.yml`.
38+
39+
Both `run` and `rm` fields are required. Projects missing either field are skipped with a warning.
40+
41+
```yaml
42+
# plugins/my-plugin/moon.yml
43+
project:
44+
metadata:
45+
raa:
46+
run: review # task to run for review build
47+
rm: review-rm # task to run for teardown
48+
```
49+
50+
The action executes `moon run <project-id>:<raa.run>` during `command: run` and `moon run <project-id>:<raa.rm>` during `command: rm`.
51+
52+
## Workflow Integration
53+
54+
RAA is dispatched from `pr.yml` via `raa.yml`:
55+
56+
1. PR push triggers `pr.yml`, which runs full CI.
57+
2. After the gate passes, if the `review-app` label is present, `pr.yml` dispatches `raa.yml` with `command: run`.
58+
3. On PR close, `pr.yml` dispatches `raa.yml` with `command: rm`.
59+
4. `raa.yml` can also be triggered manually from the Actions tab.
60+
61+
## How It Works
62+
63+
**`run` command:**
64+
65+
1. Discovers affected projects with valid `raa` metadata.
66+
2. Deactivates any existing deployments for the environment.
67+
3. Creates a new GitHub Deployment.
68+
4. Runs each project's `raa.run` task sequentially.
69+
5. Sets deployment status to `success` or `failure`.
70+
71+
**`rm` command:**
72+
73+
1. Reads the deployment manifest to find projects.
74+
2. Runs each project's `raa.rm` task.
75+
3. Deactivates and deletes the deployment.
76+
4. Deletes the GitHub environment.

.github/workflows/gh-settings.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# .github/workflows/gh-settings.yml
2+
#
3+
# Example workflow for the calling repo (astro-bay). Plan on PR, apply on push
4+
# to main. This is the workflow each project repo ships.
5+
6+
name: GitHub Settings
7+
8+
on:
9+
push:
10+
branches: [main]
11+
paths:
12+
- ".github/repo-settings.yml"
13+
- ".github/workflows/gh-settings.yml"
14+
pull_request:
15+
paths:
16+
- ".github/repo-settings.yml"
17+
- ".github/workflows/gh-settings.yml"
18+
19+
concurrency:
20+
group: gh-settings-${{ github.ref }}
21+
cancel-in-progress: false
22+
23+
jobs:
24+
settings:
25+
name: Reconcile
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 10
28+
permissions:
29+
contents: read
30+
pull-requests: write
31+
issues: write
32+
steps:
33+
- uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 1
36+
37+
# Local invocation while iterating. Swap to the published ref once the
38+
# action lives in your-org/github-management.
39+
- uses: ./.github/actions/gh-settings
40+
with:
41+
mode: ${{ github.event_name == 'push' && 'apply' || 'plan' }}
42+
github-token: ${{ secrets.GH_SETTINGS_TOKEN }}
43+
# oras-registry: ghcr.io/your-org/repo-state # enable when ready

.github/workflows/pr.yml

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,19 @@ jobs:
137137
permissions:
138138
actions: write
139139
steps:
140-
- uses: actions/github-script@v7
140+
- uses: actions/checkout@v4
141141
with:
142-
script: |
143-
await github.rest.actions.createWorkflowDispatch({
144-
...context.repo,
145-
workflow_id: 'raa.yml',
146-
ref: context.payload.pull_request.head.ref,
147-
inputs: {
148-
command: 'run',
149-
'pr-number': String(context.payload.pull_request.number),
150-
},
151-
})
142+
fetch-depth: 1
143+
- name: Dispatch RAA run
144+
run: |
145+
gh workflow run raa.yml \
146+
--ref "$HEAD_REF" \
147+
-f command=run \
148+
-f pr-number="$PR_NUMBER"
149+
env:
150+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
151+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
152+
PR_NUMBER: ${{ github.event.pull_request.number }}
152153

153154
# Teardown review environment on PR close.
154155
review-teardown:
@@ -161,15 +162,15 @@ jobs:
161162
permissions:
162163
actions: write
163164
steps:
164-
- uses: actions/github-script@v7
165+
- uses: actions/checkout@v4
165166
with:
166-
script: |
167-
await github.rest.actions.createWorkflowDispatch({
168-
...context.repo,
169-
workflow_id: 'raa.yml',
170-
ref: context.repo.default_branch,
171-
inputs: {
172-
command: 'rm',
173-
'pr-number': String(context.payload.pull_request.number),
174-
},
175-
})
167+
fetch-depth: 1
168+
- name: Dispatch RAA teardown
169+
run: |
170+
gh workflow run raa.yml \
171+
--ref main \
172+
-f command=rm \
173+
-f pr-number="$PR_NUMBER"
174+
env:
175+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176+
PR_NUMBER: ${{ github.event.pull_request.number }}

.moon/tasks/gh-pkg-npm.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
$schema: "https://moonrepo.dev/schemas/tasks.json"
2+
3+
inheritedBy:
4+
tags: ["gh-pkg-npm"]
5+
order: 30
6+
7+
tasks:
8+
publish:
9+
command: "bash"
10+
args:
11+
- "-c"
12+
- >
13+
set -euo pipefail;
14+
PR="$RAA_PR_NUMBER";
15+
SHA=$(git rev-parse --short HEAD);
16+
PKG_NAME=$(jq -r .name package.json);
17+
BASE_VERSION=$(jq -r .version package.json);
18+
PREVIEW_VERSION="${BASE_VERSION}-pr.${PR}.${SHA}";
19+
TAG="pr-${PR}";
20+
echo "Publishing ${PKG_NAME}@${PREVIEW_VERSION} to GitHub Packages with tag ${TAG}";
21+
npm version "${PREVIEW_VERSION}" --no-git-tag-version;
22+
npm publish --registry https://npm.pkg.github.com --tag "${TAG}"
23+
toolchains: ["javascript", "node"]
24+
options:
25+
runInCI: true
26+
cache: false
27+
28+
unpublish:
29+
command: "bash"
30+
args:
31+
- "-c"
32+
- >
33+
set -euo pipefail;
34+
PR="$RAA_PR_NUMBER";
35+
PKG_NAME=$(jq -r .name package.json);
36+
TAG="pr-${PR}";
37+
echo "Unpublishing ${PKG_NAME}@${TAG} from GitHub Packages";
38+
VERSION=$(npm view "${PKG_NAME}@${TAG}" version --registry https://npm.pkg.github.com 2>/dev/null || true);
39+
if [ -n "${VERSION}" ]; then
40+
npm unpublish "${PKG_NAME}@${VERSION}" --registry https://npm.pkg.github.com;
41+
echo "Unpublished ${PKG_NAME}@${VERSION}";
42+
else
43+
echo "No version found for tag ${TAG}, skipping";
44+
fi
45+
toolchains: ["javascript", "node"]
46+
options:
47+
runInCI: true
48+
cache: false

.moon/templates/astro-plugin/moon.yml.tera

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ toolchains:
55
enabled: true
66

77
tags:
8-
- 'astro-plugin'
8+
- "gh-pkg-npm"
9+
- "astro-plugin"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
$schema: "https://moonrepo.dev/schemas/project.json"
2+
3+
tags:
4+
- "gh-pkg-npm"
5+
6+
project:
7+
metadata:
8+
raa:
9+
run: publish
10+
rm: unpublish

plugins/content-hub/moon.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@ toolchains:
55
enabled: true
66

77
tags:
8+
- "gh-pkg-npm"
89
- "astro-plugin"
10+
11+
project:
12+
metadata:
13+
raa:
14+
run: publish
15+
rm: unpublish

plugins/jsonld/moon.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@ toolchains:
55
enabled: true
66

77
tags:
8+
- "gh-pkg-npm"
89
- "astro-plugin"
10+
11+
project:
12+
metadata:
13+
raa:
14+
run: publish
15+
rm: unpublish

plugins/pagefind-resolve/moon.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
$schema: "https://moonrepo.dev/schemas/project.json"
22

33
tags:
4+
- "gh-pkg-npm"
45
- "astro-plugin"
6+
7+
project:
8+
metadata:
9+
raa:
10+
run: publish
11+
rm: unpublish

plugins/taxonomy/moon.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
$schema: "https://moonrepo.dev/schemas/project.json"
22

33
tags:
4+
- "gh-pkg-npm"
45
- "astro-plugin"
6+
7+
project:
8+
metadata:
9+
raa:
10+
run: publish
11+
rm: unpublish

0 commit comments

Comments
 (0)