Skip to content

Commit 5415ae0

Browse files
added release_url to component build (#113)
* added release_url to component build * Send git attributes of vars.BUILD_DB_PACKAGES to generate-build-metadata.bash * Added /releases section to git url * deploy-2-start.yml: Added tag to the end of the pkg_release_url * deploy-2-start.yml: Enable and activate spack * deploy-2-start.yml: Get version from spack.lock * deploy-2-start.yml: Added further comments --------- Co-authored-by: Tommy Gatti <[email protected]>
1 parent 05cf79e commit 5415ae0

File tree

5 files changed

+61
-8
lines changed

5 files changed

+61
-8
lines changed

.github/workflows/deploy-2-start.yml

+46-5
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,61 @@ jobs:
114114
spack env activate ${{ inputs.env-name }}
115115
spack --debug install --fresh ${{ vars.SPACK_INSTALL_PARALLEL_JOBS }} || exit $?
116116
spack module tcl refresh -y
117+
EOT
118+
119+
- name: Get metadata from ${{ inputs.deployment-environment }}
120+
env:
121+
SPACK_ENV_PATH: ${{ steps.path.outputs.spack }}/var/spack/environments/${{ inputs.env-name }}
122+
run: |
123+
ssh ${{ secrets.USER}}@${{ secrets.HOST }} -i ${{ steps.ssh.outputs.private-key-path }} /bin/bash <<'EOT'
124+
. ${{ steps.path.outputs.spack-config }}/spack-enable.bash
125+
spack env activate ${{ inputs.env-name }}
126+
127+
spack find --paths > ${{ env.SPACK_ENV_PATH }}/spack.location
128+
spack find --format '{hash} {prefix}' | jq --raw-input --null-input '[inputs | split(" ") | {(.[0]): (.[1])}] | add' > ${{ env.SPACK_ENV_PATH }}/spack.location.json
129+
130+
# Get the repos associated with the packages for the build database
131+
jq -n '{}' > ${{ env.SPACK_ENV_PATH }}/build-db-pkgs.json
132+
for pkg in ${{ vars.BUILD_DB_PACKAGES }}; do
133+
# TODO: Is there a way to get the git attribute without concretizing?
134+
pkg_repo_url=$(spack python -c "import spack.spec; print(spack.spec.Spec('$pkg').concretized().package.git)")
117135
118-
# Obtain metadata
119-
spack find --paths > ${{ steps.path.outputs.spack }}/var/spack/environments/${{ inputs.env-name }}/spack.location
120-
spack find --format '{hash} {prefix}' | jq --raw-input --null-input '[inputs | split(" ") | {(.[0]): (.[1])}] | add' > ${{ steps.path.outputs.spack }}/var/spack/environments/${{ inputs.env-name }}/spack.location.json
136+
# We get the version of $pkg from spack.lock, and then strip
137+
# potential 'git.' and '=VERSION' parts from 'git.TAG=VERSION'
138+
version=$(jq --compact-output --raw-output \
139+
--arg p "$pkg" \
140+
'.concrete_specs | to_entries[].value | select(.name == $p) | .version
141+
| match("^(?:git.)?([^=]*)")
142+
| .captures[0].string' \
143+
${{ env.SPACK_ENV_PATH}}/spack.lock
144+
)
145+
146+
# Example:
147+
# pkg_repo_url = https://github.com/ACCESS-NRI/MOM5.git, which is then stripped of the '.git'.
148+
# version = 2024.08.11, giving
149+
# pkg_release_url = https://github.com/ACCESS-NRI/MOM5/releases/tag/2024.08.11
150+
pkg_release_url="${pkg_repo_url%.*}/releases/tag/${version}"
151+
152+
echo "$pkg pkg_repo_url is $pkg_repo_url, pkg_release_url is $pkg_release_url, version is $version"
153+
jq \
154+
--arg p "$pkg" \
155+
--arg r "$pkg_release_url" \
156+
'. += {($p): ($r)}' \
157+
${{ env.SPACK_ENV_PATH }}/build-db-pkgs.json > ${{ env.SPACK_ENV_PATH }}/build-db-pkgs.json.tmp
158+
mv -f ${{ env.SPACK_ENV_PATH }}/build-db-pkgs.json.tmp ${{ env.SPACK_ENV_PATH }}/build-db-pkgs.json
159+
done
121160
122161
spack env deactivate
123-
echo "$(date): Deployed ${{ inputs.model }} ${{ inputs.version }} with spack-packages ${{ steps.versions.outputs.packages }}, spack-config ${{ steps.versions.outputs.config }}" >> ${{ steps.path.outputs.root }}/release.log
124162
EOT
125163
126164
# Release
127165
- name: Get Release Metadata
166+
env:
167+
# TODO: Can we put both envs above in a $GITHUB_ENV file instead?
168+
SPACK_ENV_PATH: ${{ steps.path.outputs.spack }}/var/spack/environments/${{ inputs.env-name }}
128169
run: |
129170
rsync -e 'ssh -i ${{ steps.ssh.outputs.private-key-path }}' \
130-
'${{ secrets.USER}}@${{ secrets.HOST_DATA }}:${{ steps.path.outputs.spack }}/var/spack/environments/${{ inputs.env-name }}/spack.*' \
171+
'${{ secrets.USER}}@${{ secrets.HOST_DATA }}:${{ env.SPACK_ENV_PATH }}/spack.*' \
131172
./${{ inputs.env-name }}
132173
133174
- name: Upload Metadata Artifact

scripts/generate-build-metadata.bash

+9-1
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,22 @@ for pkg in "${packages[@]}"; do
7575
"$json_dir/spack.location.json"
7676
)
7777

78+
release_url=$(jq --raw-output \
79+
--arg pkg "$pkg" \
80+
'.[$pkg]' \
81+
"$json_dir/build-db-pkgs.json"
82+
)
83+
7884
component=$(jq \
7985
--arg pkg "$pkg" \
8086
--arg install_path "$install_path" \
87+
--arg release_url "$release_url" \
8188
'.concrete_specs | to_entries[] | select(.value.name == $pkg)
8289
| {
8390
spack_hash: .key,
8491
spec: (.value.name + "@" + .value.version),
85-
install_path: $install_path
92+
install_path: $install_path,
93+
release_url: $release_url
8694
}' "$json_dir/spack.lock"
8795
)
8896

tools/release_provenance/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ComponentBuild(Base):
2626
spack_hash = Column(String, primary_key=True, index=True)
2727
spec = Column(String, nullable=False)
2828
install_path = Column(String, nullable=False, unique=True)
29+
release_url = Column(Text, nullable=False, unique=True)
2930
model_build = relationship('ModelBuild', secondary="model_component", back_populates='component_build')
3031

3132
class ModelStatusEnum(enum.Enum):

tools/release_provenance/save_release.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def get_component_build(component_build_data_list, model_build):
1919
component_build.install_path = component_build_data["install_path"]
2020
component_build.spack_hash = component_build_data["spack_hash"]
2121
component_build.spec = component_build_data["spec"]
22+
component_build.release_url = component_build_data["release_url"]
2223
component_build.model_build.append(model_build)
2324
component_build_list.append(component_build)
2425
else:

tools/release_provenance/test_release_data.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
{
44
"spack_hash": "ewcdbrfukblyjxpkhd3mfkj4yxfolal8",
55
"spec": "[email protected]=2023.11.09",
6-
"install_path": "/g/data/vk83/apps/spack/0.20/release/linux-rocky8-x86_64/intel-19.0.5.280/"
6+
"install_path": "/g/data/vk83/apps/spack/0.20/release/linux-rocky8-x86_64/intel-19.0.5.280/",
7+
"release_url": "https://github.com/ACCESS-NRI/mom5/releases"
78
},
89
{
910
"spack_hash": "ewcdbrfukblyjxpkhd3mfkj4yxfolal9",
1011
"spec": "[email protected]=2023.11.09",
11-
"install_path": "/g/data/vk83/apps/spack/0.20/release/linux-rocky8-x86_64/intel-19.1.5.283/"
12+
"install_path": "/g/data/vk83/apps/spack/0.20/release/linux-rocky8-x86_64/intel-19.1.5.283/",
13+
"release_url": "https://github.com/ACCESS-NRI/mom5-example/releases"
1214
}
1315
],
1416
"model_build": {

0 commit comments

Comments
 (0)