sync-extensions.yml 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "Sync extensions ${{ env.NOW }}"
  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.NOW }}" \
  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_ENV
  60. - name: Merge Pull Request
  61. run: |
  62. # Merge the PR using the GitHub CLI
  63. gh pr merge ${{ env.PR_NUMBER }} --admin --delete-branch --merge --repo ${{ github.repository }}
  64. - name: Run chart-releaser
  65. uses: helm/chart-releaser-action@v1.5.0
  66. with:
  67. charts_dir: ./charts/*
  68. env:
  69. CR_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
  70. CR_SKIP_EXISTING: true