Nav apraksta

4_bumper_repository.yml 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. name: Repository bumper
  2. run-name: Bump ${{ github.ref_name }} (${{ inputs.id }})
  3. on:
  4. workflow_dispatch:
  5. inputs:
  6. version:
  7. description: 'Target version (e.g. 1.2.3)'
  8. default: ''
  9. required: false
  10. type: string
  11. stage:
  12. description: 'Version stage (e.g. alpha0)'
  13. default: ''
  14. required: false
  15. type: string
  16. tag:
  17. description: 'Change branches references to tag-like references (e.g. v4.12.0-alpha7)'
  18. default: false
  19. required: false
  20. type: boolean
  21. issue-link:
  22. description: 'Issue link in format https://github.com/wazuh/<REPO>/issues/<ISSUE-NUMBER>'
  23. required: true
  24. type: string
  25. id:
  26. description: 'Optional identifier for the run'
  27. required: false
  28. type: string
  29. jobs:
  30. bump:
  31. name: Repository bumper
  32. runs-on: ubuntu-22.04
  33. permissions:
  34. contents: write
  35. pull-requests: write
  36. env:
  37. CI_COMMIT_AUTHOR: wazuhci
  38. CI_COMMIT_EMAIL: 22834044+wazuhci@users.noreply.github.com
  39. CI_GPG_PRIVATE_KEY: ${{ secrets.CI_WAZUHCI_GPG_PRIVATE }}
  40. GH_TOKEN: ${{ secrets.CI_WAZUHCI_BUMPER_TOKEN }}
  41. BUMP_SCRIPT_PATH: tools/repository_bumper.sh
  42. BUMP_LOG_PATH: tools
  43. steps:
  44. - name: Dump event payload
  45. run: |
  46. cat $GITHUB_EVENT_PATH | jq '.inputs'
  47. - name: Set up GPG key
  48. id: signing_setup
  49. run: |
  50. echo "${{ env.CI_GPG_PRIVATE_KEY }}" | gpg --batch --import
  51. KEY_ID=$(gpg --list-secret-keys --with-colons | awk -F: '/^sec/ {print $5; exit}')
  52. echo "gpg_key_id=$KEY_ID" >> $GITHUB_OUTPUT
  53. - name: Set up git
  54. run: |
  55. git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
  56. git config --global user.email "${{ env.CI_COMMIT_EMAIL }}"
  57. git config --global commit.gpgsign true
  58. git config --global user.signingkey "${{ steps.signing_setup.outputs.gpg_key_id }}"
  59. echo "use-agent" >> ~/.gnupg/gpg.conf
  60. echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf
  61. echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf
  62. echo RELOADAGENT | gpg-connect-agent
  63. export DEBIAN_FRONTEND=noninteractive
  64. export GPG_TTY=$(tty)
  65. - name: Checkout repository
  66. uses: actions/checkout@v4
  67. with:
  68. # Using workflow-specific GITHUB_TOKEN because currently CI_WAZUHCI_BUMPER_TOKEN
  69. # doesn't have all the necessary permissions
  70. token: ${{ env.GH_TOKEN }}
  71. - name: Determine branch name
  72. id: vars
  73. env:
  74. VERSION: ${{ inputs.version }}
  75. STAGE: ${{ inputs.stage }}
  76. TAG: ${{ inputs.tag }}
  77. run: |
  78. script_params=""
  79. version=${{ env.VERSION }}
  80. stage=${{ env.STAGE }}
  81. tag=${{ env.TAG }}
  82. # Both version and stage provided
  83. if [[ -n "$version" && -n "$stage" && "$tag" != "true" ]]; then
  84. script_params="--version ${version} --stage ${stage}"
  85. elif [[ -n "$version" && -n "$stage" && "$tag" == "true" ]]; then
  86. script_params="--version ${version} --stage ${stage} --tag ${tag}"
  87. fi
  88. issue_number=$(echo "${{ inputs.issue-link }}" | awk -F'/' '{print $NF}')
  89. BRANCH_NAME="enhancement/wqa${issue_number}-bump-${{ github.ref_name }}"
  90. echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
  91. echo "script_params=${script_params}" >> $GITHUB_OUTPUT
  92. - name: Create and switch to bump branch
  93. run: |
  94. git checkout -b ${{ steps.vars.outputs.branch_name }}
  95. - name: Make version bump changes
  96. run: |
  97. echo "Running bump script"
  98. bash ${{ env.BUMP_SCRIPT_PATH }} ${{ steps.vars.outputs.script_params }}
  99. - name: Commit and push changes
  100. run: |
  101. git add .
  102. git commit -m "feat: bump ${{ github.ref_name }}"
  103. git push origin ${{ steps.vars.outputs.branch_name }}
  104. - name: Create pull request
  105. id: create_pr
  106. run: |
  107. gh auth setup-git
  108. PR_URL=$(gh pr create \
  109. --title "Bump ${{ github.ref_name }} branch" \
  110. --body "Issue: ${{ inputs.issue-link }}" \
  111. --base ${{ github.ref_name }} \
  112. --head ${{ steps.vars.outputs.branch_name }})
  113. echo "Pull request created: ${PR_URL}"
  114. echo "pull_request_url=${PR_URL}" >> $GITHUB_OUTPUT
  115. - name: Merge pull request
  116. run: |
  117. # Any checks for the PR are bypassed since the branch is expected to be functional (i.e. the bump process does not introduce any bugs)
  118. gh pr merge "${{ steps.create_pr.outputs.pull_request_url }}" --merge --admin
  119. - name: Show logs
  120. run: |
  121. echo "Bump complete."
  122. echo "Branch: ${{ steps.vars.outputs.branch_name }}"
  123. echo "PR: ${{ steps.create_pr.outputs.pull_request_url }}"
  124. echo "Bumper scripts logs:"
  125. cat ${BUMP_LOG_PATH}/repository_bumper*log