forked from purescript/purescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·168 lines (142 loc) · 5.96 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·168 lines (142 loc) · 5.96 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
set -ex
# Provides expanders that group console output in GitHub Actions
# See https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#grouping-log-lines
(echo "::group::Initialize variables") 2>/dev/null
# This is the main CI build script. It is intended to run on all platforms we
# run CI on: linux, mac os, and windows. It makes use of the following
# environment variables:
#
# - CI_RELEASE
#
# If set to "true", passes the RELEASE flag to the compiler, and enables
# optimizations. Otherwise, we disable optimizations (to speed builds up).
#
# = Source distributions
#
# During a normal build, we create a source distribution with `stack sdist`,
# and then compile and run tests inside that. The reason for this is that it
# helps catch issues arising from forgetting to list files which are necessary
# for compilation or for tests in our package.yaml file (these sorts of issues
# don't test to get noticed until after releasing otherwise).
# We test with --haddock because haddock generation can fail if there is invalid doc-comment syntax,
# and these failures are very easy to miss otherwise.
STACK="stack --no-terminal --haddock --jobs=2"
STACK_OPTS="--test"
if [ "$CI_RELEASE" = "true" -o "$CI_PRERELEASE" = "true" ]
then
STACK_OPTS="$STACK_OPTS --flag=purescript:RELEASE"
else
STACK_OPTS="$STACK_OPTS --fast"
fi
(echo "::endgroup::"; echo "::group::Set version number for build") 2>/dev/null
if [ "$CI_PRERELEASE" = "true" ]
then
git fetch --depth=1 origin "v$(npm view purescript@next version)"
# List of files/folders to use to detect if a new prerelease should be
# issued. Any path that could contain files that affect the built bundles or
# the published npm package should be included here. Paths that no longer
# exist should be deleted. A false positive is not as big a deal as a false
# negative, so err on the side of including stuff.
if git diff --quiet FETCH_HEAD HEAD -- \
.github/workflows app bundle ci npm-package src \
purescript.cabal stack.yaml
then
echo "Skipping prerelease because no input affecting the published package was"
echo "changed since the last prerelease"
echo "::set-output name=do-not-prerelease::true"
else
do_prerelease=true
fi
fi
package_version=$(node -pe 'require("./npm-package/package.json").version')
package_release_version=${package_version%%-*}
package_prerelease_suffix=${package_version#$package_release_version}
if ! grep -q "\"install-purescript --purs-ver=${package_version//./\\.}\"" npm-package/package.json
then
echo "Version in npm-package/package.json doesn't match version in install-purescript call"
exit 1
fi
if ! grep -q "^version:\\s*${package_release_version//./\\.}$" purescript.cabal
then
echo "Version in npm-package/package.json doesn't match version in purescript.cabal"
exit 1
fi
if ! grep -q "^prerelease = \"${package_prerelease_suffix//./\\.}\"$" app/Version.hs
then
echo "Version in npm-package/package.json doesn't match prerelease in app/Version.hs"
exit 1
fi
if [ "$do_prerelease" ]
then
function largest-matching-git-tag {
grep -E "^${1//./\\.}(\\.|$)" "$git_tags" | head -n 1
}
git_tags=$(mktemp)
trap 'rm "$git_tags"' EXIT
git ls-remote --tags -q --sort=-version:refname | sed 's_^.*refs/tags/__' > $git_tags
pushd npm-package
if [ "$package_prerelease_suffix" ]
then
tag=$(largest-matching-git-tag "v$package_release_version${package_prerelease_suffix%%.*}")
if [ "$tag" ]
then
npm version --allow-same-version "$tag"
build_version=$(npm version --no-git-tag-version prerelease)
build_version=${build_version#v}
else
build_version=$package_version
fi
else # (current version does not contain a prerelease suffix)
if grep -Fqx "v$package_release_version" "$git_tags"
then # (the current version has been published)
bump=patch
if [ "$(find ../CHANGELOG.d -maxdepth 1 -name 'breaking_*' -print -quit)" ]
then
# If we ever reach 1.0, change this to major and uncomment the below
bump=minor
#elif [ "$(find ../CHANGELOG.d -maxdepth 1 -name 'feature_*' -print -quit)" ]
#then
# bump=minor
fi
next_tag=$(npm version --no-git-tag-version "$bump")
tag=$(largest-matching-git-tag "$next_tag-[0-9]+")
if [ "$tag" ]
then
npm version --allow-same-version "$tag"
build_version=$(npm version --no-git-tag-version prerelease)
else
build_version=$(npm version --allow-same-version "$next_tag-0")
fi
build_version=${build_version#v}
else # (current version has not been published)
build_version=$package_version
echo "::set-output name=do-not-prerelease::true"
fi
fi
echo "::set-output name=version::$build_version"
popd
if [ "$build_version" != "$package_version" ]
then
build_release_version=${build_version%%-*}
build_prerelease_suffix=${build_version#$build_release_version}
# We don't need to update the install-purescript command before we build;
# we'll do that when we publish. All we need to update here are the files
# that affect the purs binary.
sed -i -e "s/^\\(version:\\s*\\)${package_release_version//./\\.}/\1$build_release_version/" purescript.cabal
sed -i -e "s/^prerelease = \"${package_prerelease_suffix//./\\.}\"$/prerelease = \"${build_prerelease_suffix}\"/" app/Version.hs
fi
fi
(echo "::endgroup::"; echo "::group::Install snapshot dependencies") 2>/dev/null
# Install snapshot dependencies (since these will be cached globally and thus
# can be reused during the sdist build step)
$STACK build --only-snapshot $STACK_OPTS
(echo "::endgroup::"; echo "::group::Build source distributions") 2>/dev/null
# Test in a source distribution (see above)
$STACK sdist . --tar-dir sdist-test;
tar -xzf sdist-test/purescript-*.tar.gz -C sdist-test --strip-components=1
(echo "::endgroup::"; echo "::group::Build and test PureScript") 2>/dev/null
pushd sdist-test
$STACK build $STACK_OPTS
popd
(echo "::endgroup::") 2>/dev/null