Skip to content

Commit c80f3aa

Browse files
authored
Spack V1 Migration Feature: Reserved Spack Definitions (#332)
* Rename action from get-spack-root-spec to get-spack-manifest, return only deployment-[name|version] * cd.yml: Use get-spack-manifest, rework job names * ci-comment.yml: Use get-spack-manifest, simplify update and commit of the bump * deploy-1-setup.yml: Use get-spack-manifest, remove check on root spec usage * deploy-2-start.yml: Remove unused manifest information * fix: Add manifest path to action * Update modules.py, prerelease.py to use reserved defs _name and _version * Update tests * Make reserved definitions flow-style for module injection too * Remove references to RootSpecs, use ReservedDefinitions.get("name"), remove --keep-root-spec-intact flag * Update pkg_repo_url logic to use spack.repo.PATH.get_pkg_class() * getter.py fixes from code review Update reserved defs getter return value, remove case statement, revert autoformatter * Update test input manifest formatting * Add back manifest info step * Update pre/release injections to handle multiple specs, simplify custom release projection logic * Change release injection --packages from space-sep to comma-sep, as convention * Update tests * Explicitly disallow multi-spec Releases * get-spack-manifest: call the getter.py script * Import yaml representers from own class * Small fixes
1 parent e51b275 commit c80f3aa

18 files changed

Lines changed: 581 additions & 385 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Get Spack Manifest Information
2+
3+
Action that returns information about a Spack manifest file.
4+
5+
## Inputs
6+
7+
> [!NOTE]
8+
> Action assumes that an appropriate repository is checked out prior to invocation
9+
10+
| Name | Type | Description | Required | Default | Example |
11+
| ---- | ---- | ----------- | -------- | ------- | ------- |
12+
| `spack-manifest-path` | `string` | The path to the spack manifest file | `false` | `"./spack.yaml"` | `"./some/other.spack.yaml"` |
13+
14+
## Outputs
15+
16+
| Name | Type | Description | Example |
17+
| ---- | ---- | ----------- | ------- |
18+
| `deployment-name` | `string` | The name of the deployment as specified in the reserved definition `_name` | `access-om2` |
19+
| `deployment-version` | `string` | The version of the deployment as specified in the reserved definition `_version` | `2025.11.000` |
20+
21+
## Example
22+
23+
```yaml
24+
# ...
25+
jobs:
26+
manifest:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- id: spec
32+
uses: access-nri/build-cd/.github/actions/get-spack-manifest@vX # for some version `vX`
33+
with:
34+
spack-manifest-path: ./spack.yaml
35+
36+
- run: |
37+
echo "Deploying ${{ steps.spec.outputs.deployment-name }} at ${{ steps.spec.outputs.deployment-version }}"
38+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Get Spack Manifest Information
2+
description: Action that returns information about a Spack manifest file
3+
author: Tommy Gatti
4+
inputs:
5+
spack-manifest-path:
6+
required: false
7+
default: ./spack.yaml
8+
description: The path to the spack manifest file
9+
outputs:
10+
deployment-name:
11+
description: |
12+
The name of the deployment as specified in the reserved definition _name, in the spack manifest file.
13+
value: ${{ steps.defs.outputs.name }}
14+
deployment-version:
15+
description: |
16+
The version of the deployment as specified in the reserved definition _version, in the spack manifest file.
17+
value: ${{ steps.defs.outputs.version }}
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Clone build-cd script location
22+
uses: actions/checkout@v4
23+
with:
24+
repository: access-nri/build-cd
25+
path: ${{ github.workspace }}/getter-script
26+
27+
- name: Get Current Directory
28+
id: script
29+
# We need to store the current working directory so we can re-construct the inputs.spack-manifest-path, as we run
30+
# the script from the build-cd directory
31+
shell: bash
32+
run: |
33+
pwd=$(pwd)
34+
echo "Action PWD: $pwd"
35+
echo "pwd=$pwd" >> $GITHUB_OUTPUT
36+
37+
- name: Get reserved definitions
38+
id: defs
39+
env:
40+
PYTHONPATH: ${{ github.workspace }}/getter-script
41+
shell: python
42+
run: |
43+
from scripts.spack_manifest.getter import ReservedDefinitions
44+
import os
45+
46+
defs = ReservedDefinitions.from_file("${{ steps.script.outputs.pwd }}/${{ inputs.spack-manifest-path }}")
47+
name = defs.get("name")
48+
version = defs.get("version")
49+
50+
with open(os.environ['GITHUB_OUTPUT'], 'a') as o:
51+
o.write(f"name={name}\n")
52+
o.write(f"version={version}\n")

.github/actions/get-spack-root-spec/README.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

.github/actions/get-spack-root-spec/action.yml

Lines changed: 0 additions & 92 deletions
This file was deleted.

.github/workflows/cd.yml

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,19 @@ jobs:
114114
target: ${{ matrix.target }}
115115
error-level: error
116116

117-
get-root-spec-ref:
118-
name: Get root spec ref
117+
get-deployment-version:
118+
name: Get Deployment Version
119119
runs-on: ubuntu-latest
120120
needs:
121121
- verify-settings
122122
outputs:
123-
root-spec-ref: ${{ steps.tag.outputs.root-spec-ref }}
123+
version: ${{ steps.manifest.outputs.deployment-version }}
124124
steps:
125125
- uses: actions/checkout@v4
126126

127-
- name: Get root spec ref
128-
id: tag
129-
uses: access-nri/build-cd/.github/actions/get-spack-root-spec@v8
127+
- name: Get Deployment Version
128+
id: manifest
129+
uses: access-nri/build-cd/.github/actions/get-spack-manifest@v8
130130
with:
131131
spack-manifest-path: ${{ inputs.spack-manifest-path }}
132132

@@ -135,7 +135,7 @@ jobs:
135135
if: inputs.tag-deployment
136136
runs-on: ubuntu-latest
137137
needs:
138-
- get-root-spec-ref
138+
- get-deployment-version
139139
permissions:
140140
contents: write
141141
steps:
@@ -155,27 +155,22 @@ jobs:
155155

156156
- name: Push Tag
157157
env:
158-
TAG: ${{ needs.get-root-spec-ref.outputs.root-spec-ref }}
158+
TAG: ${{ needs.get-deployment-version.outputs.version }}
159159
run: |
160-
if [[ "${{ env.TAG }}" == "latest" ]]; then
161-
echo "::error::The version 'latest' is reserved for a spack package that moves often and cannot be used as a release tag. Reset the 'main' or 'backport' branch, reopen the merged PR, and update the version."
162-
exit 1
163-
fi
164-
165160
git tag ${{ env.TAG }} -m "Deployment of ${{ inputs.model }} ${{ env.TAG }} via build-cd 'cd.yml' workflow"
166161
git push --tags
167162
168163
deploy-release:
169164
name: Deploy Release
170165
needs:
171166
- defaults
172-
- get-root-spec-ref
167+
- get-deployment-version
173168
- push-tag
174169
# Pushing tags is optional if we are doing a non-model deployment
175170
if: >-
176171
always() &&
177172
needs.defaults.result == 'success' &&
178-
needs.get-root-spec-ref.result == 'success' &&
173+
needs.get-deployment-version.result == 'success' &&
179174
(needs.push-tag.result == 'success' || needs.push-tag.result == 'skipped')
180175
strategy:
181176
matrix:
@@ -185,7 +180,7 @@ jobs:
185180
deployment-target: ${{ matrix.target }}
186181
deployment-ref: ${{ github.ref_name }}
187182
deployment-type: Release
188-
deployment-version: ${{ needs.get-root-spec-ref.outputs.root-spec-ref }}
183+
deployment-version: ${{ needs.get-deployment-version.outputs.version }}
189184
spack-manifest-path: ${{ inputs.spack-manifest-path }}
190185
expected-root-spec-name: ${{ needs.defaults.outputs.root-sbd }}
191186
spack-manifest-schema-path: ${{ inputs.spack-manifest-schema-path }}
@@ -204,7 +199,7 @@ jobs:
204199
if: inputs.tag-deployment
205200
needs:
206201
- defaults
207-
- get-root-spec-ref
202+
- get-deployment-version
208203
- push-tag
209204
- deploy-release
210205
runs-on: ubuntu-latest
@@ -245,7 +240,7 @@ jobs:
245240
id: release-body
246241
env:
247242
J2_MODEL: ${{ inputs.model }}
248-
J2_VERSION: ${{ needs.get-root-spec-ref.outputs.root-spec-ref }}
243+
J2_VERSION: ${{ needs.get-deployment-version.outputs.version }}
249244
J2_ROOT_SBD: ${{ needs.defaults.outputs.root-sbd }}
250245
run: |
251246
python -m scripts.jinja_template.render_deployment_info \
@@ -256,8 +251,8 @@ jobs:
256251
- name: Create Release
257252
uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87 # v2.0.5
258253
with:
259-
tag_name: ${{ needs.get-root-spec-ref.outputs.root-spec-ref }}
260-
name: ${{ inputs.model}} ${{ needs.get-root-spec-ref.outputs.root-spec-ref }}
254+
tag_name: ${{ needs.get-deployment-version.outputs.version }}
255+
name: ${{ inputs.model}} ${{ needs.get-deployment-version.outputs.version }}
261256
body_path: ${{ env.TEMPLATED_RELEASE_BODY_PATH }}
262257
generate_release_notes: true
263258
fail_on_unmatched_files: true

.github/workflows/ci-comment.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373

7474
- name: Original version
7575
id: original
76-
uses: access-nri/build-cd/.github/actions/get-spack-root-spec@v8
76+
uses: access-nri/build-cd/.github/actions/get-spack-manifest@v8
7777

7878
- name: Setup
7979
id: setup
@@ -99,11 +99,11 @@ jobs:
9999
echo "version=${tag_date}" >> $GITHUB_OUTPUT
100100
echo "bump=major" >> $GITHUB_OUTPUT
101101
else
102-
echo "version=${{ steps.original.outputs.root-spec-ref }}" >> $GITHUB_OUTPUT
102+
echo "version=${{ steps.original.outputs.deployment-version }}" >> $GITHUB_OUTPUT
103103
echo "bump=current" >> $GITHUB_OUTPUT
104104
fi
105105
elif [[ "${{ contains(github.event.comment.body, 'minor')}}" == "true" ]]; then
106-
echo "version=${{ steps.original.outputs.root-spec-ref }}" >> $GITHUB_OUTPUT
106+
echo "version=${{ steps.original.outputs.deployment-version }}" >> $GITHUB_OUTPUT
107107
echo "bump=minor" >> $GITHUB_OUTPUT
108108
else
109109
echo "::warning::Usage: `!bump [major|minor]`, got `${{ github.event.comment.body }}`"
@@ -131,22 +131,17 @@ jobs:
131131
git_tag_gpgsign: true
132132

133133
- name: Update, Commit and Push the Bump
134-
env:
135-
# If the root spec contained an '=VERSION' segment, we want to add that back to the updated root spec, too
136-
OPTIONAL_VERSION: ${{ steps.original.outputs.root-spec-version != '' && format('={0}', steps.original.outputs.root-spec-version) || '' }}
137134
run: |
138-
updated_spec="${{ needs.defaults.outputs.root-sbd }}@git.${{ steps.bump.outputs.after }}${{ env.OPTIONAL_VERSION }}"
139-
yq -i "${{ steps.original.outputs.yq-root-spec }} = \"$updated_spec\"" spack.yaml
140-
yq -i '${{ env.SPACK_YAML_MODEL_PROJECTION_YQ }} = "{name}/${{ steps.bump.outputs.after }}"' spack.yaml
135+
yq -i '.spack.definitions[]._version[0] = "${{ steps.bump.outputs.after }}"' spack.yaml
141136
git add spack.yaml
142-
git commit -m "spack.yaml: Updated ${{ needs.defaults.outputs.root-sbd }} package version from ${{ steps.original.outputs.root-spec-ref }} to ${{ steps.bump.outputs.after }}"
137+
git commit -m "spack.yaml: Updated deployment version from ${{ steps.original.outputs.deployment-version }} to ${{ steps.bump.outputs.after }}"
143138
git push
144139
145140
- name: Success Notifier
146141
uses: access-nri/actions/.github/actions/pr-comment@main
147142
with:
148143
comment: |
149-
:white_check_mark: Version bumped from `${{ steps.original.outputs.root-spec-ref }}` to `${{ steps.bump.outputs.after }}` :white_check_mark:
144+
:white_check_mark: Version bumped from `${{ steps.original.outputs.deployment-version }}` to `${{ steps.bump.outputs.after }}` :white_check_mark:
150145
151146
- name: Failure Notifier
152147
if: failure()

0 commit comments

Comments
 (0)