Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GitHub workflows for builds and releases #30

Merged
merged 2 commits into from
Jun 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 44 additions & 22 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,29 @@ jobs:
with:
mode: "install"

check-version:
runs-on: ubuntu-latest
steps:
- name: "📥 Checkout code"
uses: actions/checkout@v4

- name: "🔍 Check package.json version"
id: check_version
run: |
PACKAGE_VERSION=$(jq -r .version < package.json)
echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_ENV
RELEASE_VERSION=${GITHUB_REF#refs/tags/}
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
if [ "${PACKAGE_VERSION}" != "${RELEASE_VERSION}" ]; then
echo "Version mismatch: package.json version (${PACKAGE_VERSION}) does not match release version (${RELEASE_VERSION})"
exit 1
else
echo "Version matches: package.json version (${PACKAGE_VERSION}) matches release version (${RELEASE_VERSION})"
fi

lint:
runs-on: ubuntu-latest
needs: [ install ]
needs: [ install, check-version ]
steps:
- name: "📥 Checkout code"
uses: actions/checkout@v4
Expand All @@ -37,7 +57,7 @@ jobs:

test:
runs-on: ubuntu-latest
needs: [ install ]
needs: [ install, check-version ]
if: false
steps:
- name: "📥 Checkout code"
Expand All @@ -53,7 +73,7 @@ jobs:

storybooks:
runs-on: ubuntu-latest
needs: [ install ]
needs: [ install, check-version ]
if: false
steps:
- name: "📥 Checkout code"
Expand All @@ -67,27 +87,9 @@ jobs:
- name: "🔨 Build storybooks"
run: yarn build-storybook

check-version:
runs-on: ubuntu-latest
needs: [ install ]
steps:
- name: "🔍 Check package.json version"
id: check_version
run: |
PACKAGE_VERSION=$(jq -r .version < package.json)
echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_ENV
RELEASE_VERSION=${GITHUB_REF#refs/tags/}
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
if [ "${PACKAGE_VERSION}" != "${RELEASE_VERSION}" ]; then
echo "Version mismatch: package.json version (${PACKAGE_VERSION}) does not match release version (${RELEASE_VERSION})"
exit 1
else
echo "Version matches: package.json version (${PACKAGE_VERSION}) matches release version (${RELEASE_VERSION})"
fi

build:
runs-on: ubuntu-latest
needs: [ install ]
needs: [ install, check-version ]
steps:
- name: "📥 Checkout code"
uses: actions/checkout@v4
Expand All @@ -99,3 +101,23 @@ jobs:

- name: "🔨 Build projects"
run: yarn build

mark-release-as-bad:
runs-on: ubuntu-latest
needs: [ check-version ]
if: ${{ failure() && needs.check-version.result == 'failure' }}
steps:
- name: Mark release as bad
uses: actions/github-script@v5
with:
script: |
const { owner, repo } = context.repo
const tag_name = context.ref.replace('refs/tags/', '')
const release = await github.repos.getReleaseByTag({ owner, repo, tag: tag_name })
await github.repos.updateRelease({
owner,
repo,
release_id: release.data.id,
name: release.data.name + ' (BAD RELEASE - version check failed)',
body: release.data.body + '\n\n:warning: This release was marked as bad because the version check failed.',
})