-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease-latest-versions.sh
150 lines (122 loc) · 3.88 KB
/
release-latest-versions.sh
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
#!/usr/bin/env bash
set -e
# Possible flags:
# --should-rerelease: Rebuild and release old versions.
# --dry-run: Don't push anything to git.
# --from-version=1.0.0: Only release versions after this version.
# Parse flags
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--should-rerelease)
SHOULD_RERELEASE=true
shift
;;
--dry-run)
DRY_RUN=true
shift
;;
--from-version=*)
FROM_VERSION="${key#*=}"
shift
;;
*)
# unknown option
shift
;;
esac
done
do_release() {
local TAG="$1"
local IS_REPACK="${2:-false}"
# The version from the tag.
local VERSION="${TAG%%+repack.*}"
VERSION="${VERSION#v}"
# If IS_REPACK is true, get the repack version from the tag.
if [ "${IS_REPACK}" = true ]; then
REPACK_VERSION="${TAG#*+repack.}"
if [ "${REPACK_VERSION}" = "${TAG}" ]; then
REPACK_VERSION=0
fi
fi
echo "Checking if version ${VERSION} exists on Composer..."
# If the version doesn't exist, return
if ! composer show --working-dir=source --available wpackagist-plugin/wp-graphql "${VERSION}" >/dev/null 2>&1; then
echo "Version ${VERSION} does not exist. Skipping..."
return
fi
echo "Building v${VERSION}"
# Replace the version of wpackagist-plugin/wp-graphql in composer.json with $VERSION
contents="$(jq --arg version "${VERSION}" '.require."wpackagist-plugin/wp-graphql" = $version' <source/composer.json)" &&
echo "${contents}" >source/composer.json
cat source/composer.json
composer update --working-dir=source
# Generate stubs
echo "Generating stubs for ${VERSION}..."
composer run-script generate
# Tag version
if [ "${IS_REPACK}" = false ]; then
if ! git rev-parse "${TAG}" >/dev/null 2>&1; then
echo "Tagging ${TAG}"
git commit --all -m "Generate stubs for WPGraphQL ${TAG}"
git tag "${TAG}"
else
echo "Tag ${TAG} already exists. Skipping..."
fi
else
REPACK_VERSION=$((REPACK_VERSION + 1))
echo "Tagging v${VERSION}+repack.${REPACK_VERSION}"
git commit --all -m "Generating stubs for WPGraphQL v${VERSION}+repack.${REPACK_VERSION}"
git tag "v${VERSION}+repack.${REPACK_VERSION}"
# Delete the old git tag locally.
echo "Deleting old tag locally..."
git tag -d "${TAG}"
# Delete the old tag on GitHub.
if [ -z "${DRY_RUN}" ]; then
echo "Deleting old tag from Origin."
git push --delete origin "${TAG}"
fi
fi
# Push to GitHub
if [ -z "${DRY_RUN}" ]; then
git push
git push --tags
git pull
git pull --tags
echo "Tags synced."
else
echo "Dry run, not pushing to GitHub"
git push --dry-run --tags
fi
}
GQL_JSON="$(wget -q -O- "https://packagist.org/packages/wp-graphql/wp-graphql.json")"
# Get every possible version from GQL_JSON. Valid versions are prefixed with `v`, followed by anything.
printf -v JQ_FILTER '.package.versions[].version | select(. | startswith("v"))'
# Sort the versions.
POSSIBLE_VERSIONS="$(jq -r "$JQ_FILTER" <<<"$GQL_JSON" | sort -V)"
# Read latest version from composer.json if no FROM_VERSION is set.
if [ -z "${FROM_VERSION}" ]; then
FROM_VERSION="$(jq -r '.require."wpackagist-plugin/wp-graphql"' <source/composer.json | sed -e 's/[^0-9.]*//g')"
fi
# Loop through all possible versions and see if they exist as tags
for POSSIBLE_VERSION in ${POSSIBLE_VERSIONS}; do
if dpkg --compare-versions "${POSSIBLE_VERSION#v}" lt "${FROM_VERSION:-1.0.0}"; then
echo "Skipping ${POSSIBLE_VERSION}"
continue
fi
echo "Checking ${POSSIBLE_VERSION}"
# Get the latest tag that starts with POSSIBLE_VERSION
MATCHED_TAG="$(git tag --list "${POSSIBLE_VERSION}^*" "${POSSIBLE_VERSION}+*" --sort=-v:refname | head -n 1)"
# If we matched a tag, check if we should rerelease it
if [ -n "${MATCHED_TAG}" ]; then
if [ -z "${SHOULD_RERELEASE}" ]; then
echo "Tag exists as ${MATCHED_TAG}. Skipping..."
continue
fi
echo "Tag exists as ${MATCHED_TAG}. Rereleasing..."
do_release "${MATCHED_TAG}" true
continue
fi
# If the tag doesn't exist, release it
do_release "${POSSIBLE_VERSION}" false
done