publish.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. name: Publish
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. crate:
  6. description: Crate
  7. required: true
  8. default: sdk/pinocchio
  9. type: choice
  10. options:
  11. - programs/associated-token-account
  12. - programs/system
  13. - programs/token
  14. - sdk/log/crate
  15. - sdk/log/macro
  16. - sdk/pinocchio
  17. - sdk/pubkey
  18. level:
  19. description: Level
  20. required: true
  21. default: patch
  22. type: choice
  23. options:
  24. - patch
  25. - minor
  26. - major
  27. - rc
  28. - beta
  29. - alpha
  30. - release
  31. - version
  32. version:
  33. description: Version (used with level "version")
  34. required: false
  35. type: string
  36. dry_run:
  37. description: Dry run
  38. required: true
  39. default: true
  40. type: boolean
  41. create_release:
  42. description: Create a GitHub release
  43. required: true
  44. type: boolean
  45. default: true
  46. env:
  47. CACHE: true
  48. jobs:
  49. semver_check:
  50. name: Check Semver
  51. runs-on: ubuntu-latest
  52. steps:
  53. - name: Git checkout
  54. uses: actions/checkout@v4
  55. - name: Setup Environment
  56. uses: ./.github/actions/setup
  57. with:
  58. cargo-cache-key: cargo-semver-checks
  59. toolchain: test
  60. components: release, semver-checks
  61. - name: Set Version
  62. run: |
  63. if [ "${{ inputs.level }}" == "version" ]; then
  64. LEVEL=${{ inputs.version }}
  65. else
  66. LEVEL=${{ inputs.level }}
  67. fi
  68. git config --global user.email "github-actions@github.com"
  69. git config --global user.name "github-actions"
  70. cargo release $LEVEL --manifest-path ${{ inputs.crate }}/Cargo.toml --no-tag --no-publish --no-push --no-confirm --execute
  71. - name: Check semver
  72. run: |
  73. pnpm semver ${{ inputs.crate }}
  74. publish_release:
  75. name: Publish
  76. runs-on: ubuntu-latest
  77. needs: semver_check
  78. permissions:
  79. contents: write
  80. steps:
  81. - name: Ensure CARGO_REGISTRY_TOKEN variable is set
  82. env:
  83. token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
  84. if: ${{ env.token == '' }}
  85. run: |
  86. echo "The CARGO_REGISTRY_TOKEN secret variable is not set"
  87. echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"."
  88. exit 1
  89. - name: Git checkout
  90. uses: actions/checkout@v4
  91. with:
  92. token: ${{ secrets.ANZA_TEAM_PAT }}
  93. - name: Setup Environment
  94. uses: ./.github/actions/setup
  95. with:
  96. cargo-cache-key: cargo-publish
  97. toolchain: test
  98. components: release
  99. solana: true
  100. - name: Build
  101. run: pnpm build-sbf ${{ inputs.crate }}
  102. - name: Test
  103. run: pnpm test ${{ inputs.crate }}
  104. - name: Set Git Author
  105. run: |
  106. git config --global user.email "github-actions@github.com"
  107. git config --global user.name "github-actions"
  108. - name: Publish Crate
  109. id: publish
  110. env:
  111. CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
  112. run: |
  113. if [ "${{ inputs.level }}" == "version" ]; then
  114. LEVEL=${{ inputs.version }}
  115. else
  116. LEVEL=${{ inputs.level }}
  117. fi
  118. if [ "${{ inputs.dry_run }}" == "true" ]; then
  119. OPTIONS="--dry-run"
  120. else
  121. OPTIONS=""
  122. fi
  123. pnpm tsx ./scripts/publish.mts ${{ inputs.crate }} $LEVEL $OPTIONS
  124. - name: Generate a changelog
  125. if: github.event.inputs.dry_run != 'true' && github.event.inputs.create_release == 'true'
  126. uses: orhun/git-cliff-action@v3
  127. with:
  128. config: ".github/cliff.toml"
  129. args: |
  130. "${{ steps.publish.outputs.old_git_tag }}"..main
  131. --include-path "${{ inputs.crate }}/**"
  132. --github-repo "${{ github.repository }}"
  133. env:
  134. OUTPUT: CHANGELOG.md
  135. GITHUB_REPO: ${{ github.repository }}
  136. - name: Create GitHub release
  137. if: github.event.inputs.dry_run != 'true' && github.event.inputs.create_release == 'true'
  138. uses: ncipollo/release-action@v1
  139. with:
  140. tag: ${{ steps.publish.outputs.new_git_tag }}
  141. bodyFile: CHANGELOG.md