-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (113 loc) · 5.99 KB
/
settings-2-deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Config Settings Deployment
on:
workflow_call:
inputs:
deployment-environment:
type: string
required: true
description: GitHub Deployment Environment Name
spack-type:
type: string
required: true
description: The type of spack deployment (eg. Prerelease, Release)
env:
CONFIG_SETTINGS_PATH: ./config/settings.json
jobs:
update-environment:
name: Update ${{ inputs.deployment-environment }} ${{ inputs.spack-type }} Settings
runs-on: ubuntu-latest
environment: ${{ inputs.deployment-environment }} ${{ inputs.spack-type }}
steps:
- uses: actions/checkout@v4
- name: Setup spack updates
id: spack
# TODO: Since we can't format any of this later json as an input for this job (see the earlier workflow) we need to do it here
# Create a newline-separated list of strings of the form "MAJOR_VERSION COMMIT_HASH" so we
# update the remotes MAJOR_VERSION/spack to COMMIT_HASH. Ex: "0.20 y7834gtbf3jf3434rr34r34ru"
run: |
updates=$(jq --compact-output --raw-output \
--arg env "${{ inputs.deployment-environment }}" \
--arg type "${{ inputs.spack-type }}" \
'.deployment[$env][$type] | to_entries[] | "\(.key) \(.value.spack)"' \
${{ env.CONFIG_SETTINGS_PATH }}
)
echo "$updates"
# For multiline output, use a heredoc. See https://github.com/orgs/community/discussions/116619#discussioncomment-8994849
echo "updates<<EOF" >> $GITHUB_OUTPUT
echo "$updates" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Setup spack-config updates
id: spack-config
run: |
updates=$(jq --compact-output --raw-output \
--arg env "${{ inputs.deployment-environment }}" \
--arg type "${{ inputs.spack-type }}" \
'.deployment[$env][$type] | to_entries[] | "\(.key) \(.value."spack-config")"' \
${{ env.CONFIG_SETTINGS_PATH }}
)
echo "$updates"
# For multiline output, use a heredoc. See https://github.com/orgs/community/discussions/116619#discussioncomment-8994849
echo "updates<<EOF" >> $GITHUB_OUTPUT
echo "$updates" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Setup SSH
id: ssh
uses: access-nri/actions/.github/actions/setup-ssh@main
with:
hosts: ${{ secrets.HOST }}
private-key: ${{ secrets.SSH_KEY }}
- name: Update Spack
continue-on-error: true
run: |
ssh ${{ secrets.USER}}@${{ secrets.HOST }} -i ${{ steps.ssh.outputs.private-key-path }} /bin/bash <<'EOT'
set +e
while read -ra update; do
version=${update[0]}
new_commit=${update[1]}
current_head_commit=$(git -C ${{ secrets.SPACK_INSTALLS_ROOT_LOCATION }}/$version/spack rev-parse HEAD)
if [ $? -eq 128 ]; then
# FIXME: Deploy spack instances in this job too.
echo "::error::Error: ${{ inputs.deployment-environment }} ${{ inputs.spack-type }} $version spack does not exist. Deploy it via build-cds Create Deployment Spack workflow first."
continue
fi
git -C ${{ secrets.SPACK_INSTALLS_ROOT_LOCATION }}/$version/spack fetch
if [[ "$current_head_commit" != "$new_commit" ]]; then
git -C ${{ secrets.SPACK_INSTALLS_ROOT_LOCATION }}/$version/spack checkout $new_commit
if [ $? -ne 0 ]; then
echo "::error::Error: ${{ inputs.deployment-environment }} ${{ inputs.spack-type }} $version spack failed checkout from $current_head_commit to $new_commit"
else
echo "::notice::Changed: ${{ inputs.deployment-environment }} ${{ inputs.spack-type }} $version spack changed from $current_head_commit to $new_commit"
fi
else
echo "::notice::Unchanged: ${{ inputs.deployment-environment }} ${{ inputs.spack-type }} $version spack left at $current_head_commit"
fi
done <<< "${{ steps.spack.outputs.updates }}"
EOT
- name: Update spack-config
continue-on-error: true
run: |
ssh ${{ secrets.USER}}@${{ secrets.HOST }} -i ${{ steps.ssh.outputs.private-key-path }} /bin/bash <<'EOT'
set +e
while read -ra update; do
version=${update[0]}
new_tag=${update[1]}
current_head_commit=$(git -C ${{ secrets.SPACK_INSTALLS_ROOT_LOCATION }}/$version/spack-config rev-parse HEAD)
if [ $? -eq 128 ]; then
echo "::error::Error: ${{ inputs.deployment-environment }} ${{ inputs.spack-type }} $version spack-config does not exist."
continue
fi
git -C ${{ secrets.SPACK_INSTALLS_ROOT_LOCATION }}/$version/spack-config fetch
# Parse the above spack-config tag as a commit hash, for easy comparison. The '^{}' syntax gives the hash of the tagged commit, not the hash of the tag itself
new_commit=$(git -C ${{ secrets.SPACK_INSTALLS_ROOT_LOCATION }}/$version/spack-config rev-parse "${new_tag}^{}")
if [[ "$current_head_commit" != "$new_commit" ]]; then
git -C ${{ secrets.SPACK_INSTALLS_ROOT_LOCATION }}/$version/spack-config checkout $new_tag
if [ $? -ne 0 ]; then
echo "::error::Error: ${{ inputs.deployment-environment }} ${{ inputs.spack-type }} $version spack-config failed checkout from $current_head_commit to $new_commit"
else
echo "::notice::Changed: ${{ inputs.deployment-environment }} ${{ inputs.spack-type }} $version spack-config changed from $current_head_commit to $new_commit"
fi
else
echo "::notice::Unchanged: ${{ inputs.deployment-environment }} ${{ inputs.spack-type }} $version spack-config left at $current_head_commit"
fi
done <<< "${{ steps.spack-config.outputs.updates }}"
EOT