-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* activate build-n-test on main branch too * temporarily test the release workflow * remove condition to test * fix naming convention step * fix yarn version syntax * Add readme and fix yarn version for alpha * Fix the yarn gitignore * Add alpha version logic to prepare-release * fix alpha script path * Try to fix ancestor branch issue for yarn * Fix git push and release creation * fix long version of setup-node commit * keep trying to fix the git push * Still figuring out yarn version on CI * Fix typo * trying out different approaches for git push from GHA * chore:Bump version to 0.0.0-alpha.0 * push new version to PR when reviewed * create releases on version bump * update README * add alpha explanaition to README * make sure only one label is applied to the PR * Update naming convention comments * make sure comments are handled even when checks fail * better messaging for PR naming * fix job URL * fix permissions for title checker * fail if naming checks are not working * fix the version bump process * fix naming checks --------- Co-authored-by: GitHub Actions <[email protected]>
- Loading branch information
1 parent
47ae92c
commit 59aa18c
Showing
9 changed files
with
194 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# GitHub Workflows Overview | ||
|
||
This repository contains several GitHub Actions workflows that automate various processes, including building, testing, versioning, and releasing your project. Below is an overview of each workflow and how they contribute to the release process. | ||
|
||
## Workflows | ||
|
||
### 1. `prepare-release.yml` | ||
|
||
This workflow is responsible for versioning and preparing releases based on pull request labels. | ||
|
||
- **Trigger**: Runs on pull request reviews that are approved. | ||
- **Version Bump**: Determines the version bump type (major, minor, patch) based on PR labels. If an `alpha` label is present, it creates a prerelease version. | ||
- **Versioning**: Uses `yarn version` to update the version in `package.json`. | ||
- **Outputs**: Provides the version type and alpha status for subsequent workflows. | ||
|
||
- **Alpha Versioning**: When a PR includes the `alpha` label, versions are created with an `-alpha.N` suffix (e.g., `1.2.3-alpha.1`, `1.2.3-alpha.2`). This continues until the alpha label is removed, at which point the version returns to standard semantic versioning. | ||
|
||
|
||
### 2. `build-test-report.yml` | ||
|
||
This workflow handles building, testing, and reporting. | ||
|
||
- **Trigger**: Runs on pull requests and pushes to the `main` branch. | ||
- **Build and Test**: Installs dependencies, builds the project, and runs tests. | ||
- **Reporting**: Uploads test results and coverage reports to Codecov. | ||
|
||
### 3. `naming-conventions.yml` | ||
|
||
This workflow ensures that pull request titles and labels follow specific conventions. | ||
|
||
- **Trigger**: Runs on various pull request events (opened, edited, labeled, etc.). | ||
- **Title Check**: Validates PR titles against the Conventional Commits specification. | ||
- **Label Check**: Ensures PRs have one of the required labels (major, minor, patch, no-release). | ||
- **Comments**: Adds or removes comments on PRs based on title and label validation results. | ||
|
||
### 4. `create-release.yml` | ||
|
||
This workflow creates a draft release on GitHub when a new version is detected in `package.json` on the `main` branch. | ||
|
||
- **Trigger**: Runs on pushes to the `main` branch. | ||
- **Version Check**: Verifies if the version in `package.json` has been updated. | ||
- **Draft Release**: Creates a draft release with the new version tag if the version check is successful. | ||
|
||
### 5. `publish-release.yml` | ||
|
||
This workflow handles the publishing of releases to NPM. | ||
|
||
- **Trigger**: Runs when a release is published on GitHub. | ||
- **Build and Publish**: Checks out the code, installs dependencies, builds the project, and publishes it to NPM. | ||
- **Provenance**: Uses `npm publish` with provenance for security. | ||
|
||
## Release Process | ||
|
||
1. **Versioning**: The `prepare-release.yml` workflow determines the version bump based on PR labels after a review has been approved. If a PR is labeled with `major`, `minor`, or `patch`, the version is updated accordingly. If labeled with `alpha`, a prerelease version is created. | ||
|
||
2. **Draft Release Creation**: The `create-release.yml` workflow creates a draft release if `package.json` contains a new version on the `main` branch. | ||
|
||
3. **Publishing**: When a release is published on GitHub (moved from draft to released), the `publish-release.yml` workflow is triggered. It builds the project and publishes it to NPM, ensuring the package is available for public use. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
# Get the current version from package.json | ||
current_version=$(node -p "require('./package.json').version") | ||
|
||
# Get the previous version from the last commit | ||
previous_version=$(git show HEAD~1:package.json | node -p "JSON.parse(require('fs').readFileSync(0, 'utf-8')).version") | ||
|
||
# Compare the versions | ||
if [ "$current_version" != "$previous_version" ]; then | ||
echo "Version has been bumped from $previous_version to $current_version." | ||
exit 0 | ||
else | ||
echo "Version has not been bumped." | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
# Read the current version from package.json | ||
current_version=$(node -p "require('./package.json').version") | ||
|
||
# Check if version contains alpha | ||
if [[ "$current_version" == *"-alpha"* ]]; then | ||
if [[ "$1" != "yes" ]]; then | ||
# Remove alpha if present and "yes" is not passed | ||
new_version="${current_version%%-alpha*}" | ||
else | ||
# Keep the current version if "yes" is passed | ||
new_version="${current_version}" | ||
fi | ||
elif [[ "$1" == "yes" ]]; then | ||
# Add alpha if not present and "yes" was passed | ||
new_version="${current_version}-alpha" | ||
else | ||
# Keep current version if no alpha and no "yes" passed | ||
new_version="${current_version}" | ||
fi | ||
|
||
# Update the package.json with the new version | ||
node -e " | ||
let pkg = require('./package.json'); | ||
pkg.version = '$new_version'; | ||
require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2)); | ||
" | ||
|
||
echo "Updated version to $new_version" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ on: | |
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-n-test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Release and Versioning | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
create-release: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write # Highly security sensitive. Do NOT add third party actions in this job | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 2 # Need at least 2 commits to compare versions | ||
|
||
- name: Check if version was bumped | ||
id: version_check | ||
run: | | ||
./.github/ci-scripts/check-version-bump.sh | ||
- name: Create GitHub Release | ||
if: success() && steps.version_check.outcome == 'success' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
VERSION=$(node -p "require('./package.json').version") | ||
gh release create "v${VERSION}" \ | ||
--title "Release v${VERSION}" \ | ||
--generate-notes \ | ||
--prerelease \ | ||
--draft |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
name: Release and Versioning | ||
name: Package version bump | ||
on: | ||
pull_request_review: | ||
types: [submitted] | ||
pull_request: | ||
types: [closed] | ||
branches: | ||
- main | ||
paths: | ||
- '.github/workflows/prepare-release.yml' | ||
|
||
jobs: | ||
get_version: | ||
if: github.event.pull_request.merged == true | ||
bump-version: | ||
runs-on: ubuntu-latest | ||
if: github.event.review.state == 'approved' | ||
permissions: | ||
contents: write # Highly security sensitive. Do NOT add third party actions in this job | ||
pull-requests: read | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.ref || github.ref_name }} | ||
fetch-depth: 0 # https://yarnpkg.com/features/release-workflow#caveat | ||
|
||
- uses: actions/setup-node@v4 | ||
- name: Show current branch | ||
run: | | ||
echo "Current branch: $(git branch --show-current)" | ||
echo "Current commit: $(git rev-parse HEAD)" | ||
git log --oneline -5 | ||
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af #@v4 | ||
with: | ||
node-version: '20' | ||
|
||
|
@@ -22,7 +35,7 @@ jobs: | |
- name: Set Yarn version | ||
run: yarn set version 4.5.0 | ||
|
||
- name: Get version bump type from labels | ||
- name: Check PR version labels | ||
id: bump | ||
run: | | ||
# Check for version type labels | ||
|
@@ -39,6 +52,7 @@ jobs: | |
# Check for alpha label | ||
if ${{ contains(github.event.pull_request.labels.*.name, 'alpha') }}; then | ||
echo "alpha=true" >> $GITHUB_OUTPUT | ||
echo "type=prerelease" >> $GITHUB_OUTPUT | ||
else | ||
echo "alpha=false" >> $GITHUB_OUTPUT | ||
fi | ||
|
@@ -47,55 +61,29 @@ jobs: | |
id: cancel | ||
if: steps.bump.outputs.type == 'no-release' | ||
run: | | ||
echo "No version bump required. Exiting successfully." | ||
exit 0 | ||
continue-on-error: true | ||
echo "::warning::No version bump required. Skipping release steps." | ||
- name: Configure Git | ||
if: steps.cancel.outcome == 'success' | ||
run: | | ||
git config --global user.name 'GitHub Action' | ||
git config --global user.email '[email protected]' | ||
- name: Bump version | ||
if: steps.cancel.outcome == 'success' | ||
- name: Toggle Alpha | ||
if: steps.bump.outputs.type != 'no-release' | ||
run: | | ||
if [ "${{ steps.bump.outputs.alpha }}" == "true" ]; then | ||
yarn version --${{ steps.bump.outputs.type }} --preid alpha | ||
./.github/ci-scripts/toggle-alpha.sh yes | ||
else | ||
yarn version --${{ steps.bump.outputs.type }} | ||
./.github/ci-scripts/toggle-alpha.sh #remove alpha if present | ||
fi | ||
- name: Bump version | ||
if: steps.bump.outputs.type != 'no-release' | ||
run: yarn version ${{ steps.bump.outputs.type }} | ||
|
||
- name: Push changes | ||
if: steps.cancel.outcome == 'success' | ||
if: steps.bump.outputs.type != 'no-release' | ||
run: | | ||
VERSION=$(node -p "require('./package.json').version") | ||
git config user.name "GitHub Actions" | ||
git config user.email "[email protected]" | ||
git add package.json | ||
git commit -am "chore:Bump version to ${VERSION}" | ||
git push | ||
git push --tags | ||
outputs: | ||
type: ${{ steps.bump.outputs.type }} | ||
alpha: ${{ steps.bump.outputs.alpha }} | ||
create-release: | ||
needs: get_version | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
if: needs.get_version.outputs.type != 'no-release' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: main | ||
|
||
- name: Create GitHub Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
VERSION=$(node -p "require('./package.json').version") | ||
if ${{ contains(github.event.pull_request.labels.*.name, 'alpha') }}; then | ||
VERSION="${VERSION}-alpha" | ||
fi | ||
gh release create "v${VERSION}" \ | ||
--title "Release v${VERSION}" \ | ||
--generate-notes \ | ||
--prerelease \ | ||
--draft | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,5 +67,6 @@ | |
}, | ||
"peerDependencies": { | ||
"viem": "^2" | ||
} | ||
}, | ||
"stableVersion": "0.0.0-alpha" | ||
} |