forked from sxs-collaboration/spectre
-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (108 loc) · 4.29 KB
/
PostRelease.yaml
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
# Distributed under the MIT License.
# See LICENSE.txt for details.
# Automations that run on published releases
name: Post release
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name of the release'
required: true
jobs:
add_spack_version:
name: Add version to Spack
# Checksum the new release and send a PR to Spack that adds the new version.
# The 'sxs-bot' GitHub account is the author of the commit and the PR.
# - This job requires a repository secret named `GH_TOKEN_SXSBOT_SPACK` that
# has write access to the `sxs-bot/spack` repository.
runs-on: ubuntu-latest
env:
RELEASE_TAG_NAME: ${{ inputs.tag_name || github.event.release.tag_name }}
steps:
- name: Download Spack
uses: actions/checkout@v4
with:
repository: spack/spack
fetch-depth: 0
token: ${{ secrets.GH_TOKEN_SXSBOT_SPACK }}
- name: Add spack-python to path
run: |
echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH
- name: Checksum new version
# Download and checksum the release tarball, and add a line to Spack's
# `spectre/package.py`` file with the new version.
#
# The package file defines versions in lines like this:
#
# version('develop', branch='develop')
# version('2022.01.03', sha256='872a0d1...')
# ...
#
# The `spack.util.format.get_version_lines` function returns a string
# with lines like this for the new version(s), including the correct
# indentation. Therefore, we insert the new lines into the file right
# below the 'develop' version.
shell: spack-python {0}
run: |
import spack.spec
import spack.stage
import spack.repo
import spack.util.format
import os
# The tag name includes the 'v' prefix
release_name = '${{ env.RELEASE_TAG_NAME }}'[1:]
# Get the URL for the release tarball. The
# 'github.event.release.tarball_url' points to a slightly different
# 'https://api.github.com/...' URL, which has a different checksum
# than the tarball listed on the GitHub release page and used by
# Spack.
pkg_cls = spack.repo.PATH.get_pkg_class('spectre')
pkg = pkg_cls(spack.spec.Spec('spectre'))
release_url = pkg.url_for_version(release_name)
url_dict = {
release_name: release_url,
}
version_hashes = spack.stage.get_checksums_for_versions(
url_dict,
pkg.name,
fetch_options=pkg.fetch_options,
)
version_lines = spack.util.format.get_version_lines(
version_hashes, url_dict
)
package_file = os.path.join(pkg.package_dir, 'package.py')
with open(package_file, 'r') as open_package_file:
package_file_lines = open_package_file.readlines()
with open(package_file, 'w') as open_package_file:
for line in package_file_lines:
open_package_file.write(line)
if line.strip().startswith('version("develop"'):
open_package_file.write(version_lines + "\n")
- name: Fix code formatting
run: |
spack style --fix `git diff --name-only`
# Formatting can also be fixed later by Spack maintainers in the PR, so
# it's fine if it fails here for some reason
continue-on-error: true
- name: Print diff
run: |
git diff
- name: Send pull request to Spack
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GH_TOKEN_SXSBOT_SPACK }}
commit-message: "spectre: add ${{ env.RELEASE_TAG_NAME }}"
committer: "sxs-bot <sxs-bot@black-holes.org>"
branch: "spectre-${{ env.RELEASE_TAG_NAME }}"
delete-branch: true
push-to-fork: sxs-bot/spack
title: "spectre: add ${{ env.RELEASE_TAG_NAME }}"
body: ""
# Build and push the `demo` container to DockerHub on releases. This is
# because the `demo` container has pre-built executables that we want to keep
# up to date.
docker:
uses: ./.github/workflows/DemoContainer.yaml
secrets: inherit