diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml index ad9f63178e..c00fff822a 100644 --- a/.github/workflows/pr-title.yml +++ b/.github/workflows/pr-title.yml @@ -12,7 +12,7 @@ jobs: env: PR_TITLE: ${{ github.event.pull_request.title }} run: | - if ! echo "$PR_TITLE" | grep -E "^(fix|feat|chore|docs)(\([a-z-]+\))?: (๐Ÿ”– )?[a-z].+[^.]$"; then + if ! echo "$PR_TITLE" | grep -E "^(fix|feat|chore|docs)(\([a-z-]+\))?: (๐Ÿ”–|๐Ÿงช )?[a-z].+[^.]$"; then echo "โŒ PR title '$PR_TITLE' does not match the required format" echo "Required format: type(scope): subject" echo "Examples:" diff --git a/.github/workflows/snapshot-pr.yaml b/.github/workflows/snapshot-pr.yaml new file mode 100644 index 0000000000..06846419d1 --- /dev/null +++ b/.github/workflows/snapshot-pr.yaml @@ -0,0 +1,44 @@ +name: Snapshot PR Creation + +on: + pull_request: + types: [labeled] + +jobs: + create-snapshot-pr: + if: github.event.label.name == 'snapshot' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Checkout main branch + uses: actions/checkout@v4 + with: + ref: main + fetch-depth: 0 + + - name: Create or update the snapshot branch + run: git push origin main:refs/heads/snapshot --force + + - name: Checkout the PR branch + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Create PR to snapshot + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_TITLE: ${{ github.event.pull_request.title }} + SOURCE_BRANCH: ${{ github.event.pull_request.head.ref }} + run: | + gh pr create \ + --base snapshot \ + --head "$SOURCE_BRANCH" \ + --title "chore: ๐Ÿงช release ($PR_TITLE)" \ + --body "This PR was automatically created from #$PR_NUMBER when the 'snapshot' label was added. + + Merging this PR will trigger a snapshot package release to the NPM registry. + You will be able to install it under the 'snapshot' tag." diff --git a/.github/workflows/snapshot-release.yaml b/.github/workflows/snapshot-release.yaml new file mode 100644 index 0000000000..2fd0233698 --- /dev/null +++ b/.github/workflows/snapshot-release.yaml @@ -0,0 +1,62 @@ +name: Snapshot Release + +on: + pull_request: + types: [closed] + branches: + - snapshot + +jobs: + release-snapshot: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 20 + cache: 'npm' + registry-url: 'https://registry.npmjs.org' + + - name: Update package versions + run: | + TIMESTAMP=$(date +%s) + VERSION="0.0.0-snapshot.$TIMESTAMP" + + # Update Core package version + jq ".version = \"$VERSION\"" packages/core/package.json > tmp.json && mv tmp.json packages/core/package.json + + # Update CLI package version and the Core dependency + jq ".version = \"$VERSION\"" packages/cli/package.json > tmp.json && mv tmp.json packages/cli/package.json + jq ".dependencies[\"@redocly/openapi-core\"] = \"$VERSION\"" packages/cli/package.json > tmp.json && mv tmp.json packages/cli/package.json + + NEW_DESCRIPTION="${{ github.event.pull_request.body }} + + Experimental release **v$VERSION**. Install it with \`npm install @redocly/cli@$VERSION\`." + + gh pr edit $PR_NUMBER --body "$NEW_DESCRIPTION" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + + - name: Install dependencies + run: npm install + + - name: Build packages + run: npm run compile + + - name: Publish snapshot packages + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + git diff + + cd packages/core + npm publish --tag snapshot + cd ../cli + npm publish --tag snapshot diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 36b1dbdb4e..7f77461ee6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -233,3 +233,13 @@ However, you can release a new version with a problematic commit reverted. Create a new branch from **main**, then find the hash of the commit you want to revert and run `git revert `. Create a patch-level changeset for the revert and open a PR with it. Merge the PR and cut a release according to the [Release flow](#release-flow). + +### Snapshot release flow + +To release an experimental version to the **NPM** registry, follow these steps: + +1. Create a new PR to **main**. +2. Add the `snapshot` label to the PR. This creates a new PR with to the `snapshot` branch (which is a copy of the `main` branch). +3. Merging the second PR triggers release to the **NPM** registry under the `snapshot` tag. + +The released version can be installed with `npm install @redocly/cli@snapshot`. diff --git a/package.json b/package.json index e851ed374b..be58d171f5 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "OpenAPI linter", "Swagger linter", "AsyncAPI linter", + "Arazzo linter", "oas" ], "contributors": [