Skip to content

Commit

Permalink
chore(ops): update semver checks to package (#2146)
Browse files Browse the repository at this point in the history
<!--  Thanks for sending a pull request! -->

#### What this PR does / why we need it:
Implement proper semver versioning for our releases. Currently, it only
allows `major.minor.patch`. It doesn't support beta/rc tags.

#### Which issue(s) does this PR fixes?:
<!--
(Optional) Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes #

#### Additional comments?:
  • Loading branch information
thedoublejay authored Aug 28, 2023
1 parent 79a4f60 commit ce3814e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 24 deletions.
7 changes: 4 additions & 3 deletions .github/scripts/release-ecr-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ module.exports = ({ context }) => {
}

function getReleaseTag(context) {
const semver = context.payload.release.tag_name
if (semver.match(/^v[0-9]+\.[0-9]+\.[0-9]+$/) === null) {
const semver = require("semver");
const version = context.payload.release.tag_name;
if (!semver.valid(version)) {
throw new Error(`Release Violation: Provided version '${semver}' is not valid semver.`)
}
return semver.replace('v','')
return version.replace('v','')
}
9 changes: 5 additions & 4 deletions .github/scripts/release-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ function getDomain(context) {
}

function getReleaseTag(domain, app, context) {
const semver = context.payload.release.tag_name
if (semver.match(/^v[0-9]+\.[0-9]+\.[0-9]+$/) === null) {
throw new Error(`Release Violation: Provided version '${semver}' is not valid semver.`)
const semver = require("semver");
const version = context.payload.release.tag_name;
if (!semver.valid(version)) {
throw new Error(`Release Violation: Provided version '${version}' is not valid semver.`)
}
return `ghcr.io/${domain}/${app}:latest,ghcr.io/${domain}/${app}:${semver.replace('v','')}`
return `ghcr.io/${domain}/${app}:latest,ghcr.io/${domain}/${app}:${version.replace('v','')}`
}

function getMainTag(domain, app, { sha }) {
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version-file: '.nvmrc'

- run: npm ci

- name: Resolve Tags
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
id: tags
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release-ecr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ jobs:
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version-file: '.nvmrc'

- run: npm ci

- name: Set up QEMU
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0

Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@ jobs:
with:
node-version-file: '.nvmrc'

- uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
- run: npm ci

- name: Resolve Version
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
id: version
with:
script: |
const semver = context.ref.replace('refs/tags/v', '')
if (semver.match(/^[0-9]+\.[0-9]+\.[0-9]+$/)) {
return semver
}
throw new Error('not semver')
script: return require('./.github/scripts/release-ecr-tags.js')({ context })
result-encoding: string

- run: npm ci
- run: npm run all:build
- run: npm run all:version ${{ steps.version.outputs.result }}

Expand Down
20 changes: 11 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"lerna": "5.1.8",
"lint-staged": "13.2.3",
"nock": "13.3.0",
"semver": "^7.5.4",
"shuffle-seed": "1.1.6",
"ts-jest": "27.1.5",
"typescript": "4.2.4",
Expand Down

0 comments on commit ce3814e

Please sign in to comment.