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

ci: use org workflows #468

Merged
merged 8 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
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
13 changes: 2 additions & 11 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,5 @@ on:

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Run Linter
run: |
npm ci
npm run lint
uses: cap-js/.github/.github/workflows/lint.yml@main
secrets: inherit
53 changes: 5 additions & 48 deletions .github/workflows/prepare-next-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,10 @@ permissions:
contents: write
pull-requests: write

env:
INPUTS_INCREMENT: ${{ github.event.inputs.increment }}
CHANGELOG_FILE: CHANGELOG.md


jobs:
create-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org/

- name: Increment version
id: increment-version
run: |
npm version $INPUTS_INCREMENT --no-git-tag-version
echo "new-version=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT

# -i for in-place editing, -E for extended regex including \s for whitespace
# double quotes needed for sed to work with variable replacement
# double backslashes needed for sed to work with double quotes
- name: Replace Unreleased entry in ${{ env.CHANGELOG_FILE }}
env:
NEW_VERSION: ${{ steps.increment-version.outputs.new-version }}
run: |
CURRENT_DATE=$(date +%Y-%m-%d)
sed -i -E "0,/^##\s+.*\[Unreleased\].*$/s//## [Unreleased]\\
\\
### Added\\
### Changed\\
### Deprecated\\
### Removed\\
### Fixed\\
### Security\\
\\
## [${NEW_VERSION}] - ${CURRENT_DATE}/" $CHANGELOG_FILE
head -n 20 $CHANGELOG_FILE

- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
commit-message: chore/release-${{ steps.increment-version.outputs.new-version }}
title: "chore(version): ${{ env.INPUTS_INCREMENT}} version ${{ steps.increment-version.outputs.new-version }}"
body: Set version to ${{ steps.increment-version.outputs.new-version }}
branch: chore/release-${{ steps.increment-version.outputs.new-version }}
reviewers: ${{ github.actor }}
prepare-next-version:
uses: cap-js/.github/.github/workflows/prepare-next-version.yml@main
secrets: inherit
with:
increment: ${{ github.event.inputs.increment }}
89 changes: 5 additions & 84 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,89 +18,10 @@ on:
permissions:
contents: write

env:
INPUTS_DRY_RUN: ${{ github.event.inputs.dry-run }}
DRY_RUN_OPTION: ${{ github.event.inputs.dry-run == 'true' && '--dry-run' || '' }}


jobs:
check-versions:
runs-on: ubuntu-latest
outputs:
do-release: ${{ steps.check-versions.outputs.do-release }}
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org/

- name: Check Versions
id: check-versions
run: |
if [ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]; then
echo "Run as workflow_dispatch: run release"
echo "do-release=true" >> $GITHUB_OUTPUT
exit 0
fi

package_name=$(npm pkg get name | tr -d '"')
local_version=$(npm pkg get version | tr -d '"')
npm_version=$(npm show $package_name version)

echo "Local version: $local_version"
echo "NPM version: $npm_version"

npm install -g semver

if semver -r ">${npm_version}" "${local_version}"; then
echo "Local version is greater than npm version: run release"
echo "do-release=true" >> $GITHUB_OUTPUT
else
echo "Local version is not greater than npm version: nothing to do."
echo "do-release=false" >> $GITHUB_OUTPUT
fi

publish-npm:
runs-on: ubuntu-latest
needs: check-versions
if: ${{ needs.check-versions.outputs.do-release == 'true' }}
environment: npm
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org/

- name: Run Unit Tests
if: ${{ github.event.inputs.dry-run != 'true' }}
run: |
npm ci
npm run test

- name: Publish to npm
run: npm publish --access public $DRY_RUN_OPTION
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

- name: Get Version
id: get-version
run: |
echo "version=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT

- name: Parse CHANGELOG.md
id: parse-changelog
uses: schwma/[email protected]
with:
version: '${{ steps.get-version.outputs.version }}'
title-regex: '^##\s+\[\d.*$'

- name: Create a GitHub release
if: ${{ github.event.inputs.dry-run != 'true' }}
uses: ncipollo/release-action@v1
with:
tag: 'v${{ steps.get-version.outputs.version }}'
body: '${{ steps.parse-changelog.outputs.body }}'
release:
uses: cap-js/.github/.github/workflows/release.yml@main
secrets: inherit
with:
dry-run: ${{ github.event.inputs.dry-run || false }}
Loading