-
Notifications
You must be signed in to change notification settings - Fork 8
Add github workflow for publishing crates #152
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
47a27db
Add github workflow for publishing crates
grod220 b0679e1
version crates
grod220 0fc980b
Review updates
grod220 bc207e7
fork learnings
grod220 c85b6a7
Remove semver check from main check
grod220 773859c
Change job name to kebab
grod220 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,153 @@ | ||
| name: Publish Rust Crate | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| package_path: | ||
| description: Path to directory with package to release | ||
| required: true | ||
| default: 'clients/cli' | ||
| type: choice | ||
| options: | ||
| - clients/cli | ||
| - program | ||
| level: | ||
| description: Level | ||
| required: true | ||
| default: patch | ||
| type: choice | ||
| options: | ||
| - patch | ||
| - minor | ||
| - major | ||
| - rc | ||
| - beta | ||
| - alpha | ||
| - release | ||
| - version | ||
| version: | ||
| description: Version (used with level "version") | ||
| required: false | ||
| type: string | ||
| dry_run: | ||
| description: Dry run | ||
| required: true | ||
| default: true | ||
| type: boolean | ||
| create_release: | ||
| description: Create a GitHub release | ||
| required: true | ||
| type: boolean | ||
| default: true | ||
|
|
||
| jobs: | ||
| main-check: | ||
| name: Main check | ||
| uses: ./.github/workflows/main.yml | ||
|
|
||
| semver: | ||
| name: Check semver after bump | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Git Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Environment | ||
| uses: ./.github/actions/setup | ||
| with: | ||
| cargo-cache-key: cargo-semver | ||
| cargo-release: true | ||
| cargo-semver-checks: true | ||
|
|
||
| - name: Set Git Author (required for cargo-release) | ||
| run: | | ||
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git config --global user.name "github-actions[bot]" | ||
|
|
||
| - name: Set Version | ||
| run: | | ||
| if [ "${{ inputs.level }}" == "version" ]; then | ||
| LEVEL=${{ inputs.version }} | ||
| else | ||
| LEVEL=${{ inputs.level }} | ||
| fi | ||
| cargo release $LEVEL --manifest-path "${{ inputs.package_path }}/Cargo.toml" --no-tag --no-publish --no-push --no-confirm --execute | ||
|
|
||
| # only successfully runs if crate is library & is not first publish | ||
| - name: Check semver | ||
| if: ${{ inputs.package_path != 'clients/cli' && inputs.level != 'release' }} | ||
|
Comment on lines
+76
to
+78
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that's clever! I never realized what "release" was for 😅 |
||
| run: pnpm rust:semver --manifest-path "${{ inputs.package_path }}/Cargo.toml" | ||
|
|
||
| publish: | ||
| name: Publish Rust Crate | ||
| runs-on: ubuntu-latest | ||
| needs: [ main-check, semver ] | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - name: Git Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.ANZA_TEAM_PAT }} | ||
| fetch-depth: 0 # get the whole history for git-cliff | ||
|
|
||
| - name: Setup Environment | ||
| uses: ./.github/actions/setup | ||
| with: | ||
| cli: true | ||
| cargo-cache-key: cargo-publish-${{ inputs.package_path }} | ||
| cargo-cache-fallback-key: cargo-publish | ||
| cargo-release: true | ||
|
|
||
| - name: Ensure CARGO_REGISTRY_TOKEN variable is set | ||
| env: | ||
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | ||
| if: ${{ env.CARGO_REGISTRY_TOKEN == '' }} | ||
| run: | | ||
| echo "The CARGO_REGISTRY_TOKEN secret variable is not set" | ||
| echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"." | ||
| exit 1 | ||
|
|
||
| - name: Set Git Author | ||
| run: | | ||
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git config --global user.name "github-actions[bot]" | ||
|
|
||
| - name: Publish Crate | ||
| id: publish | ||
| env: | ||
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | ||
| run: | | ||
| if [ "${{ inputs.level }}" == "version" ]; then | ||
| LEVEL=${{ inputs.version }} | ||
| else | ||
| LEVEL=${{ inputs.level }} | ||
| fi | ||
|
|
||
| if [ "${{ inputs.dry_run }}" == "true" ]; then | ||
| OPTIONS="--dry-run" | ||
| else | ||
| OPTIONS="" | ||
| fi | ||
|
|
||
| pnpm rust:publish "${{ inputs.package_path }}" $LEVEL $OPTIONS | ||
|
|
||
| - name: Generate a changelog | ||
| if: github.event.inputs.create_release == 'true' | ||
| uses: orhun/git-cliff-action@v3 | ||
| with: | ||
| config: "scripts/cliff.toml" | ||
| args: | | ||
| "${{ steps.publish.outputs.old_git_tag }}"..main | ||
| --include-path "${{ inputs.package_path }}/**" | ||
| --github-repo "${{ github.repository }}" | ||
| env: | ||
| OUTPUT: TEMP_CHANGELOG.md | ||
| GITHUB_REPO: ${{ github.repository }} | ||
|
|
||
| - name: Create GitHub release | ||
| if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true' | ||
| uses: ncipollo/release-action@v1 | ||
| with: | ||
| tag: ${{ steps.publish.outputs.new_git_tag }} | ||
| bodyFile: TEMP_CHANGELOG.md | ||
This file contains hidden or 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 hidden or 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,58 @@ | ||
| # git-cliff configuration file | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| # https://git-cliff.org/docs/configuration | ||
| # | ||
| # Lines starting with "#" are comments. | ||
| # Configuration options are organized into tables and keys. | ||
| # See documentation for more information on available options. | ||
|
|
||
| [changelog] | ||
| header = """ | ||
| ## What's new | ||
| """ | ||
| # template for the changelog body | ||
| # https://tera.netlify.app/docs | ||
| body = """ | ||
| {% for group, commits in commits | group_by(attribute="group") %}\ | ||
| {% for commit in commits %} | ||
| - {{ commit.message | upper_first | split(pat="\n") | first | trim }}\ | ||
| {% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif %}\ | ||
| {% endfor %}\ | ||
| {% endfor %} | ||
| """ | ||
| # remove the leading and trailing whitespace from the template | ||
| trim = true | ||
| footer = """ | ||
| """ | ||
| postprocessors = [] | ||
| [git] | ||
| # parse the commits based on https://www.conventionalcommits.org | ||
| conventional_commits = true | ||
| # filter out the commits that are not conventional | ||
| filter_unconventional = false | ||
| # process each line of a commit as an individual commit | ||
| split_commits = false | ||
| # regex for preprocessing the commit messages | ||
| commit_preprocessors = [] | ||
| # regex for parsing and grouping commits | ||
| commit_parsers = [ | ||
| { message = "^build\\(deps\\)", skip = true }, | ||
| { message = "^build\\(deps-dev\\)", skip = true }, | ||
| { message = "^ci", skip = true }, | ||
| { body = ".*", group = "Changes" }, | ||
| ] | ||
| # protect breaking changes from being skipped due to matching a skipping commit_parser | ||
| protect_breaking_commits = false | ||
| # filter out the commits that are not matched by commit parsers | ||
| filter_commits = false | ||
| # glob pattern for matching git tags | ||
| tag_pattern = "v[0-9]*" | ||
| # regex for skipping tags | ||
| skip_tags = "" | ||
| # regex for ignoring tags | ||
| ignore_tags = "" | ||
| # sort the tags topologically | ||
| topo_order = false | ||
| # sort the commits inside sections by oldest/newest order | ||
| sort_commits = "newest" | ||
| # limit the number of commits included in the changelog. | ||
| # limit_commits = 42 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's helpful if these checks can run for PRs against any branches