diff --git a/.github/workflows/pre_release.yaml b/.github/workflows/pre_release.yaml deleted file mode 100644 index a46364d..0000000 --- a/.github/workflows/pre_release.yaml +++ /dev/null @@ -1,92 +0,0 @@ -name: Create a pre-release - -on: - # Push to master will deploy a beta version - push: - branches: - - master - tags-ignore: - - "**" # Ignore all tags to prevent duplicate builds when tags are pushed. - -concurrency: - group: release - cancel-in-progress: false - -jobs: - release_metadata: - if: "!startsWith(github.event.head_commit.message, 'docs') && !startsWith(github.event.head_commit.message, 'ci') && startsWith(github.repository, 'apify/')" - name: Prepare release metadata - runs-on: ubuntu-latest - outputs: - version_number: ${{ steps.release_metadata.outputs.version_number }} - changelog: ${{ steps.release_metadata.outputs.changelog }} - steps: - - uses: apify/workflows/git-cliff-release@main - name: Prepare release metadata - id: release_metadata - with: - release_type: prerelease - existing_changelog_path: CHANGELOG.md - - update_changelog: - needs: [ release_metadata ] - name: Update changelog - runs-on: ubuntu-latest - outputs: - changelog_commitish: ${{ steps.commit.outputs.commit_long_sha || github.sha }} - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} - - - name: Use Node.js 22 - uses: actions/setup-node@v4 - with: - node-version: 22 - - - name: Update package version in package.json - run: npm version --no-git-tag-version --allow-same-version ${{ needs.release_metadata.outputs.version_number }} - - - name: Update CHANGELOG.md - uses: DamianReeves/write-file-action@master - with: - path: CHANGELOG.md - write-mode: overwrite - contents: ${{ needs.release_metadata.outputs.changelog }} - - - name: Commit changes - id: commit - uses: EndBug/add-and-commit@v9 - with: - author_name: Apify Release Bot - author_email: noreply@apify.com - message: "chore(release): Update changelog and package version [skip ci]" - - publish_to_npm: - name: Publish to NPM - needs: [ update_changelog ] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ needs.update_changelog.outputs.changelog_commitish }} - - name: Use Node.js 22 - uses: actions/setup-node@v4 - with: - node-version: 22 - - name: Install dependencies - run: | - echo "access=public" >> .npmrc - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc - npm install - - # Check version consistency and increment pre-release version number for beta only. - name: Bump pre-release version - run: node ./.github/scripts/before-beta-release.js - - name: Publish to NPM - run: npm publish --tag beta - -env: - NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }} - NPM_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }} diff --git a/.github/workflows/publish_to_npm.yaml b/.github/workflows/publish_to_npm.yaml new file mode 100644 index 0000000..e25ffa3 --- /dev/null +++ b/.github/workflows/publish_to_npm.yaml @@ -0,0 +1,116 @@ +name: Publish to NPM + +# Bumps the package version, generates changelog, creates a git tag, publishes to NPM, and creates a GitHub release. + +on: + workflow_dispatch: + inputs: + bump: + description: 'Version bump' + required: true + type: choice + default: 'patch' + options: + - 'major' + - 'minor' + - 'patch' + - 'none' # Use 'none' to just publish the current version without bumping, useful if version is set manually. + +permissions: + contents: write + id-token: write + +jobs: + publish: + name: Publish + runs-on: ubuntu-latest + steps: + - name: Check if branch is `master` + if: github.ref != 'refs/heads/master' + run: | + echo "This workflow can only be run on the master branch." + exit 1 + + - name: Checkout repository + uses: actions/checkout@v6 + with: + token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} + fetch-depth: 0 # Fetch all history for tags + + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: 24 + + - name: Install dependencies + run: npm install + + - name: Bump version + if: ${{ inputs.bump != 'none' }} + run: npm version ${{ inputs.bump }} --no-git-tag-version + + - name: Get current version + id: get_version + run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + + # We need to create a commit and tag for the new version so that git-cliff can + # get the current version to generate the changelog. + # This commit will be ignored by git-cliff because of its title. + - name: Commit version bump + run: | + # Add a newline to CHANGELOG.md so that there is always a change to commit, even if the version was bumped manually before. + # CHANGELOG.md will be regenerated later with git-cliff, so this is a noop. + echo "" >> CHANGELOG.md + git config user.name "Apify Release Bot" + git config user.email "noreply@apify.com" + git add . + git commit -m "chore(release): Release new version [skip ci]" + git tag "v${{ steps.get_version.outputs.VERSION }}" + + - name: Generate full changelog + id: git-cliff + uses: orhun/git-cliff-action@v4 + env: + OUTPUT: CHANGELOG.md + + - name: Amend commit with updated changelog + run: | + git add CHANGELOG.md + git commit --amend --no-edit + # Move the tag to point to the amended commit + git tag -f "v${{ steps.get_version.outputs.VERSION }}" + + - name: Publish to NPM + run: npm publish + + - name: Push changes + run: git push origin $(git rev-parse --abbrev-ref HEAD) --tags + + # Generate release notes only from the current version + - name: Generate changelog for release notes + id: git-cliff-release-notes + uses: orhun/git-cliff-action@v4 + with: + args: --current --strip all + + - name: Format release notes + id: format-release-notes + env: + # Pass input as environment variable to prevent injection issues in the script + UNFORMATTED_RELEASE_NOTES: ${{ steps.git-cliff-release-notes.outputs.content }} + run: | + # Git cliff outputs the version at the top, we don't need that in the release notes. + # We can simply skip the first two lines and then trim any leading/trailing whitespace. + FORMATTED_RELEASE_NOTES=$(echo "${UNFORMATTED_RELEASE_NOTES}" | tail -n +3 | sed '/^$/d') + { + echo "formatted_release_notes<> $GITHUB_OUTPUT + + - name: Create release + uses: softprops/action-gh-release@v2 + with: + tag_name: "v${{ steps.get_version.outputs.VERSION }}" + name: "v${{ steps.get_version.outputs.VERSION }}" + body: ${{ steps.format-release-notes.outputs.formatted_release_notes }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index f95d605..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,119 +0,0 @@ -name: Create a release - -on: - # Trigger a stable version release via GitHub's UI, with the ability to specify the type of release. - workflow_dispatch: - inputs: - release_type: - description: Release type - required: true - type: choice - default: auto - options: - - auto - - custom - - patch - - minor - - major - custom_version: - description: The custom version to bump to (only for "custom" type) - required: false - type: string - default: "" - -concurrency: - group: release - cancel-in-progress: false - -jobs: - release_metadata: - name: Prepare release metadata - runs-on: ubuntu-latest - outputs: - version_number: ${{ steps.release_metadata.outputs.version_number }} - tag_name: ${{ steps.release_metadata.outputs.tag_name }} - changelog: ${{ steps.release_metadata.outputs.changelog }} - release_notes: ${{ steps.release_metadata.outputs.release_notes }} - steps: - - uses: apify/workflows/git-cliff-release@main - name: Prepare release metadata - id: release_metadata - with: - release_type: ${{ inputs.release_type }} - custom_version: ${{ inputs.custom_version }} - existing_changelog_path: CHANGELOG.md - - update_changelog: - needs: [ release_metadata ] - name: Update changelog - runs-on: ubuntu-latest - outputs: - changelog_commitish: ${{ steps.commit.outputs.commit_long_sha || github.sha }} - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} - - - name: Use Node.js 22 - uses: actions/setup-node@v4 - with: - node-version: 22 - - - name: Update package version in package.json - run: npm version --no-git-tag-version --allow-same-version ${{ needs.release_metadata.outputs.version_number }} - - - name: Update CHANGELOG.md - uses: DamianReeves/write-file-action@master - with: - path: CHANGELOG.md - write-mode: overwrite - contents: ${{ needs.release_metadata.outputs.changelog }} - - - name: Commit changes - id: commit - uses: EndBug/add-and-commit@v9 - with: - author_name: Apify Release Bot - author_email: noreply@apify.com - message: "chore(release): Update changelog and package version [skip ci]" - - create_github_release: - name: Create github release - needs: [release_metadata, update_changelog] - runs-on: ubuntu-latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - name: Create release - uses: softprops/action-gh-release@v2 - with: - tag_name: ${{ needs.release_metadata.outputs.tag_name }} - name: ${{ needs.release_metadata.outputs.version_number }} - target_commitish: ${{ needs.update_changelog.outputs.changelog_commitish }} - body: ${{ needs.release_metadata.outputs.release_notes }} - - publish_to_npm: - name: Publish to NPM - needs: [ update_changelog ] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ needs.update_changelog.outputs.changelog_commitish }} - - name: Use Node.js 22 - uses: actions/setup-node@v4 - with: - node-version: 22 - - name: Install dependencies - run: | - echo "access=public" >> .npmrc - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc - npm install - - name: Publish to NPM - run: npm publish --tag latest - -env: - NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }} - NPM_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }} diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 0000000..b4d0a9f --- /dev/null +++ b/cliff.toml @@ -0,0 +1,61 @@ +# git-cliff ~ configuration file +# https://git-cliff.org/docs/configuration + +[changelog] +# A Tera template to be rendered as the changelog's header. +# See https://keats.github.io/tera/docs/#introduction +header = """ +# Changelog +""" +# A Tera template to be rendered for each release in the changelog. +# See https://keats.github.io/tera/docs/#introduction +body = """ +{% if version %}\ +## {{ version | trim_start_matches(pat="v") }} - {{ timestamp | date(format="%Y-%m-%d") }} +{% else %} +## Unreleased +{% endif %} +{% if version == "v0.0.1" %}\ +Initial release. +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %}\ +### {{ group | upper_first }} +{% for commit in commits %}- {{ commit.message | upper_first }} +{% endfor %} +{% endfor %} +""" +# A Tera template to be rendered as the changelog's footer. +# See https://keats.github.io/tera/docs/#introduction +footer = """""" +# Remove leading and trailing whitespaces from the changelog's body. +trim = false +# Remove HTML comments +postprocessors = [ + { pattern = "", replace = "" } +] +[git] +# Parse commits according to the conventional commits specification. +# See https://www.conventionalcommits.org +conventional_commits = true +# Exclude commits that do not match the conventional commits specification. +filter_unconventional = true +# Split commits on newlines, treating each line as an individual commit. +split_commits = false +# An array of regex based parsers for extracting data from the commit message. +# Assigns commits to groups. +# Optionally sets the commit's scope and can decide to exclude commits from further processing. +commit_parsers = [ + { message = "^feat", group = "Features" }, + { message = "^fix", group = "Bug Fixes" }, + { message = "^chore\\(release\\)", skip = true }, + { message = "^(docs|chore\\(docs\\))", skip = true }, + { message = "^(ci|chore\\(ci\\))", skip = true }, + { message = "^chore", group = "Chores" }, +] +# Exclude commits that are not matched by any commit parser. +filter_commits = true +# Order releases topologically instead of chronologically. +topo_order = false +# Order of commits in each group/release within the changelog. +# Allowed values: newest, oldest +sort_commits = "oldest"