sync-extensions.yml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. name: Sync and Release Extensions
  2. on:
  3. push:
  4. branches:
  5. - main
  6. paths:
  7. - manifest.json
  8. env:
  9. ACTIONS_RUNNER_DEBUG: false
  10. CI_COMMIT_MESSAGE: CI Build Artifacts
  11. GH_TOKEN: ${{ github.token }}
  12. jobs:
  13. sync:
  14. if: github.repository_owner == 'rancher'
  15. name: Sync and Release Extensions
  16. runs-on: ubuntu-latest
  17. permissions: write-all
  18. steps:
  19. - name: Checkout
  20. uses: actions/checkout@v3
  21. - name: Configure Git
  22. run: |
  23. git config user.name github-actions
  24. git config user.email github-actions@github.com
  25. - name: Setup Helm
  26. uses: azure/setup-helm@v3
  27. with:
  28. version: v3.12.1
  29. - name: Run sync script
  30. shell: bash
  31. id: sync_script
  32. run: |
  33. chmod +x ./scripts/sync
  34. ./scripts/sync
  35. - name: Generate branch name based on date and time
  36. run: echo "NOW=$(date +'%Y-%m-%d-%H-%M-%S')" >> $GITHUB_ENV
  37. - name: Commit Changes and push to a branch
  38. run: |
  39. git checkout -b sync-${{ env.NOW }}
  40. git add ./{assets,charts,extensions,icons,index.yaml}
  41. git commit -a -m "${{ env.CI_COMMIT_MESSAGE }}"
  42. git push origin sync-${{ env.NOW }}
  43. - name: Create Pull Request
  44. run: |
  45. # Create the PR using the GitHub CLI
  46. pr_number=$(gh pr create \
  47. --title "Create PR for extension sync: ${{ env.CI_COMMIT_MESSAGE }}" \
  48. --body "This PR was automatically created by a GitHub Action." \
  49. --base main \
  50. --head sync-${{ env.NOW }} \
  51. --fill \
  52. --repo ${{ github.repository }} | awk '{print $NF}') # Get the PR URL and Extract the last element (the PR number)
  53. # Check if pr_number is empty (creation failed)
  54. if [ -z "$pr_number" ]; then
  55. echo "Failed to create PR."
  56. exit 1
  57. fi
  58. # Store the PR number as an output
  59. echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
  60. - name: Run chart-releaser
  61. uses: helm/chart-releaser-action@v1.5.0
  62. with:
  63. charts_dir: ./charts/*
  64. env:
  65. CR_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
  66. CR_SKIP_EXISTING: true
  67. merge-pr:
  68. needs: sync
  69. runs-on: ubuntu-latest
  70. steps:
  71. - name: Merge Pull Request
  72. run: |
  73. # Merge the PR using the GitHub CLI
  74. gh pr merge ${{ needs.create-pr.outputs.pr_number }} --merge --repo ${{ github.repository }}
  75. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}