Skip to content

Commit f83f495

Browse files
authored
Make workflow patches less brittle. (#97)
1 parent 24a35bf commit f83f495

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

.github/bump-version.bump.sh

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ for V in ${CURRENTVERS} ${RELEASEVERS} ; do
3434
echo "Illegal zero version '${V}'" 1>&2
3535
exit 1
3636
fi
37-
# Sanity check: Must be valid semver.
38-
if ! [[ ${V} =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]] ; then
37+
# Sanity check: Must start with a valid semver.
38+
if ! [[ ${V} =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))? ]] ; then
3939
echo "Invalid version '${V}'" 1>&2
4040
exit 1
4141
fi
@@ -48,27 +48,24 @@ if [ -z "${RELEASEVERS}" ] ; then
4848
RELEASEVERS="${CURRENTVERS/-*}"
4949
;;
5050
"prerelease")
51-
# Split "1.2.3-pre.4" into "1.2.3" and "pre.4".
52-
read -r PRE POST < <(echo "${CURRENTVERS/-/ }")
53-
# Remove non-numeric parts of "pre.4" like "pre".
54-
POST="$(echo "${POST}" | sed -e 's/[^0-9.]//g' -e 's/\.*$//')"
55-
# Remove leading, trailing, or repeated "." characters.
56-
POST="$(echo "${POST}" | sed -e 's/^\.*//' -e 's/\.*$//' -e 's/\.\.*/./g')"
57-
if [ "${POST}" = "" ] ; then
58-
POST="0"
51+
# Replace [-.]pre[-.$] with [-.]rc[-.$].
52+
RELEASEVERS="$(echo "${CURRENTVERS}" | sed -E 's/([-.])pre([-.]|$)/\1rc\2/')"
53+
# If no [-.]rc[-.$], append -rc.0.
54+
if ! [[ ${RELEASEVERS} =~ [-.]rc([-.]|$) ]] ; then
55+
RELEASEVERS="${RELEASEVERS}-rc.0"
5956
fi
60-
# Set "1.2.3-rc.4".
61-
RELEASEVERS="${PRE}-rc.${POST}"
6257
;;
6358
esac
6459
fi
6560
echo "::set-output name=release::${RELEASEVERS}"
6661

6762
# Derive a new bumped version from the release version.
68-
# Change "1.2.3-rc.4" to "1.2.3.4".
69-
VERSION="$(echo "${RELEASEVERS}" | sed -e 's/-/./g' -e 's/rc//' -e 's/\.\.*/./g')"
70-
# Increment "1.2.3.4" to "1.2.3.5".
71-
VERSION="$(echo "${VERSION}" | awk -F. -v OFS=. '{$NF += 1 ; print}')"
72-
# Convert back to valid semver syntax "1.2.3-pre.5".
73-
VERSION="$(echo "${VERSION}" | sed -e 's/\([^.]*\)\.\([^.]*\)\.\([^.]*\)\(\.\(.*\)\)\{0,1\}/\1.\2.\3-pre.\5/' -e 's/\.$//')"
63+
# Increment the last number in the string.
64+
VERSION="$(echo "${RELEASEVERS}" | gawk '{ start=match($0, /(.*)([0-9]+)([^0-9]*)$/, a) ; a[2] += 1 ; printf("%s%s%s", a[1], a[2], a[3]) }')"
65+
# Replace [-.]rc[-.$] with pre.
66+
VERSION="$(echo "${VERSION}" | sed -E 's/([-.])rc([-.]|$)/\1pre\2/')"
67+
# If no [-.]pre[-.$], then append -pre.
68+
if ! [[ ${VERSION} =~ [-.]pre([-.]|$) ]] ; then
69+
VERSION="${VERSION}-pre"
70+
fi
7471
echo "::set-output name=bumped::${VERSION}"

.github/bump-version.get.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ if [ "${CURRENTVERS/-*/}" = "0.0.0" ] ; then
9898
echo "Illegal zero version '${CURRENTVERS}'" 1>&2
9999
exit 1
100100
fi
101-
# Sanity check: Must be valid semver.
102-
if ! [[ ${CURRENTVERS} =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]] ; then
101+
# Sanity check: Must start with a valid semver.
102+
if ! [[ ${CURRENTVERS} =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))? ]] ; then
103103
echo "Invalid version '${CURRENTVERS}'" 1>&2
104104
exit 1
105105
fi

.github/typescript-ci-patch.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
value: "${{ matrix.system.os }}"
4343

4444
# These steps are lifted from the Rust CI workflow, cargo-test job.
45+
- op: test
46+
path: /jobs/test/steps/2/name
47+
value: Install modules
4548
- op: add
4649
path: /jobs/test/steps/2
4750
value:
@@ -62,6 +65,9 @@
6265
run: yarn run compile
6366

6467
# Only check coverage in one of the matrix job instances.
68+
- op: test
69+
path: /jobs/test/steps/6/name
70+
value: Check test coverage
6571
- op: add
6672
path: /jobs/test/steps/6/if
6773
value: ${{ contains(matrix.system.os, 'ubuntu') && matrix.node_version == '16' && matrix.rust_version == 'stable' && github.base_ref != '' }}
@@ -98,12 +104,21 @@
98104
value:
99105
run: echo RUSTFLAGS="-C target-feature=-crt-static" >> "${GITHUB_ENV}"
100106
# We don't need to run setup-node inside of a node docker image.
107+
- op: test
108+
path: /jobs/test-docker/steps/3/uses
109+
value: actions/setup-node@v3
101110
- op: remove
102111
path: /jobs/test-docker/steps/3
103112
# No need to check test coverage here, since we do it in the first matrix build.
113+
- op: test
114+
path: /jobs/test-docker/steps/7/name
115+
value: Check test coverage
104116
- op: remove
105117
path: /jobs/test-docker/steps/7
106118

119+
- op: test
120+
path: /jobs/test/steps/6/name
121+
value: Check test coverage
107122
- op: replace
108123
path: /jobs/test/steps/6/with/afterSwitchCommand
109-
value: yarn install --ignore-scripts && yarn run compile
124+
value: yarn install --ignore-scripts && yarn run compile

.github/workflows/update-workflows.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ jobs:
7272
\ ] ; then\n (\n echo \"- op: replace\"\n echo \" path: /on/schedule/0/cron\"\
7373
\n echo \" value: \\\"$(( $RANDOM % 60 )) 7 * * 1\\\"\"\n ) > thisrepo/.github/update-workflows-patch.yaml\n\
7474
\ # \"git add\" and commit will be taken care of below.\nfi\nif [ -f thisrepo/.github/workflows/rebuild.yaml\
75-
\ ] && ! [ -f thisrepo/.github/workflows/rebuild-patch.yaml ] ; then\n (\n\
76-
\ echo \"- op: replace\"\n echo \" path: /on/schedule/0/cron\"\n \
77-
\ echo \" value: \\\"$(( $RANDOM % 60 )) 16 * * 2\\\"\"\n ) > thisrepo/.github/rebuild-patch.yaml\n\
75+
\ ] && ! [ -f thisrepo/.github/rebuild-patch.yaml ] ; then\n (\n echo\
76+
\ \"- op: replace\"\n echo \" path: /on/schedule/0/cron\"\n echo \"\
77+
\ value: \\\"$(( $RANDOM % 60 )) 16 * * 2\\\"\"\n ) > thisrepo/.github/rebuild-patch.yaml\n\
7878
fi\n"
7979
- name: Update workflows
8080
id: update

0 commit comments

Comments
 (0)