Skip to content

Commit 647ece6

Browse files
authored
Make workflow patches less brittle. (#84)
1 parent 0c0c4ca commit 647ece6

File tree

6 files changed

+49
-50
lines changed

6 files changed

+49
-50
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/rust-ci-patch.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
- op: add
2-
path: /jobs/cargo-test/steps/1/with/target
3-
value: wasm32-unknown-unknown
4-
- op: add
5-
path: /jobs/cargo-test/steps/2
6-
value:
7-
uses: IronCoreLabs/[email protected]
8-
with:
9-
crate: wasm-bindgen-cli
10-
accesskey: AKIAU2WBY6VDTC563V7G
11-
secretkey: ${{ secrets.TOOL_CACHE_SECRET_KEY }}
12-
os: ubuntu-20.04
131
- op: remove
142
path: /jobs/coverage
153
- op: remove

.github/rust-daily-patch.yaml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1+
- op: test
2+
path: /jobs/cargo-check/steps/1/uses
3+
value: actions-rs/toolchain@v1
14
- op: add
25
path: /jobs/cargo-check/steps/1/with/target
36
value: wasm32-unknown-unknown
47
- op: add
58
path: /jobs/cargo-check/steps/2
69
value:
7-
uses: IronCoreLabs/[email protected]
8-
with:
9-
crate: wasm-bindgen-cli
10-
accesskey: AKIAU2WBY6VDTC563V7G
11-
secretkey: ${{ secrets.TOOL_CACHE_SECRET_KEY }}
12-
os: ubuntu-20.04
10+
uses: IronCoreLabs/[email protected]
11+
with:
12+
crate: wasm-bindgen-cli
13+
accesskey: AKIAU2WBY6VDTC563V7G
14+
secretkey: ${{ secrets.TOOL_CACHE_SECRET_KEY }}
15+
os: ubuntu-20.04
1316
# Run cargo update so our lock file's wasm-bindgen matches the latest wasm-bindgen-cli
17+
- op: test
18+
path: /jobs/cargo-check/steps/6/run
19+
value: cargo check --all-features
1420
- op: add
1521
path: /jobs/cargo-check/steps/6
1622
value:
17-
run: cargo update
23+
run: cargo update

.github/typescript-ci-patch.yaml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,25 @@
1010
- op: add
1111
path: /jobs/test/steps/2
1212
value:
13-
uses: IronCoreLabs/[email protected]
14-
with:
15-
crate: wasm-bindgen-cli
16-
accesskey: AKIAU2WBY6VDTC563V7G
17-
secretkey: ${{ secrets.TOOL_CACHE_SECRET_KEY }}
18-
os: ubuntu-20.04
13+
uses: IronCoreLabs/[email protected]
14+
with:
15+
crate: wasm-bindgen-cli
16+
accesskey: AKIAU2WBY6VDTC563V7G
17+
secretkey: ${{ secrets.TOOL_CACHE_SECRET_KEY }}
18+
os: ubuntu-20.04
19+
20+
- op: test
21+
path: /jobs/test/steps/5/name
22+
value: Run tests
1923
- op: add
2024
path: /jobs/test/steps/5
2125
value:
22-
name: Compile
23-
run: cargo update && yarn run compile
26+
name: Compile
27+
run: cargo update && yarn run compile
28+
2429
# Coverage doesn't work for this repo
30+
- op: test
31+
path: /jobs/test/steps/7/name
32+
value: Check test coverage
2533
- op: remove
2634
path: /jobs/test/steps/7

.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)