release.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. name: Create Release
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. version:
  6. description: 'version to release, e.g. v1.5.13'
  7. required: true
  8. default: 'v0.1.0'
  9. source_ref:
  10. description: 'source ref to publish from. E.g.: main'
  11. required: true
  12. default: 'main'
  13. env:
  14. IMAGE_NAME: ghcr.io/${{ github.repository }}
  15. permissions:
  16. contents: read
  17. jobs:
  18. release:
  19. name: Create Release
  20. runs-on: ubuntu-latest
  21. permissions:
  22. contents: write # to create a release and push new docs
  23. steps:
  24. - name: Harden the runner (Audit all outbound calls)
  25. uses: step-security/harden-runner@fe104658747b27e96e4f7e80cd0a94068e53901d # v2.16.1
  26. with:
  27. egress-policy: audit
  28. - name: Checkout
  29. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  30. with:
  31. fetch-depth: 0
  32. - name: Resolve and validate ref
  33. id: resolve_ref
  34. env:
  35. SOURCE_REF: ${{ github.event.inputs.source_ref }}
  36. run: |
  37. set -e
  38. # Try to fetch the ref from remote
  39. if git fetch origin "$SOURCE_REF"; then
  40. # Remote ref exists, use it
  41. RESOLVED_SHA=$(git rev-parse "origin/$SOURCE_REF")
  42. elif git rev-parse --verify "$SOURCE_REF" >/dev/null 2>&1; then
  43. # Local ref exists (e.g., a tag)
  44. RESOLVED_SHA=$(git rev-parse "$SOURCE_REF")
  45. else
  46. echo "Error: ref '$SOURCE_REF' not found"
  47. exit 1
  48. fi
  49. echo "Resolved to SHA: $RESOLVED_SHA"
  50. echo "sha=$RESOLVED_SHA" >> $GITHUB_OUTPUT
  51. - name: Checkout validated ref
  52. run: git checkout ${{ steps.resolve_ref.outputs.sha }}
  53. - name: Create Release
  54. uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe # v2.6.1
  55. with:
  56. tag_name: ${{ github.event.inputs.version }}
  57. target_commitish: ${{ github.event.inputs.source_ref }}
  58. generate_release_notes: true
  59. body: |
  60. Image: `${{ env.IMAGE_NAME }}:${{ github.event.inputs.version }}`
  61. Image: `${{ env.IMAGE_NAME }}:${{ github.event.inputs.version }}-ubi`
  62. Image: `${{ env.IMAGE_NAME }}:${{ github.event.inputs.version }}-ubi-boringssl`
  63. env:
  64. GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
  65. - name: Configure Git
  66. env:
  67. TOKEN: ${{ secrets.GITHUB_TOKEN }}
  68. run: |
  69. git config user.name "$GITHUB_ACTOR"
  70. git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
  71. git remote set-url origin "https://x-access-token:${{ env.TOKEN }}@github.com/${{ github.repository }}.git"
  72. - name: Update Docs
  73. if: github.ref == 'refs/heads/main'
  74. env:
  75. DOCS_VERSION: ${{ github.event.inputs.version }}
  76. GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
  77. run: make docs.publish DOCS_ALIAS=latest
  78. promote:
  79. name: Promote Container Image
  80. runs-on: ubuntu-latest
  81. strategy:
  82. matrix:
  83. include:
  84. - tag_suffix: "" # distroless image
  85. - tag_suffix: "-ubi" # ubi image
  86. - tag_suffix: "-ubi-boringssl" # ubi image
  87. permissions:
  88. contents: write #to update the github release
  89. id-token: write #for keyless sign
  90. packages: write #to update packages with added SBOMs.
  91. env:
  92. SOURCE_TAG: ${{ github.event.inputs.source_ref }}${{ matrix.tag_suffix }}
  93. RELEASE_TAG: ${{ github.event.inputs.version }}${{ matrix.tag_suffix }}
  94. steps:
  95. - uses: step-security/harden-runner@fe104658747b27e96e4f7e80cd0a94068e53901d # v2.16.1
  96. with:
  97. egress-policy: audit
  98. - name: Checkout
  99. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  100. with:
  101. fetch-depth: 0
  102. - name: Setup Go
  103. uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
  104. id: setup-go
  105. with:
  106. go-version-file: "go.mod"
  107. - name: Download Go modules
  108. run: go mod download
  109. - name: Login to Docker
  110. uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
  111. with:
  112. registry: ghcr.io
  113. username: ${{ github.actor }}
  114. password: ${{ secrets.GITHUB_TOKEN }}
  115. - name: Promote Container Image
  116. run: make docker.promote
  117. - name: Build release manifests
  118. env:
  119. RELEASE_VERSION: ${{ github.event.inputs.version }}
  120. run: |
  121. # temporarily patch the version so we generate manifests with the new version
  122. yq e -i ".version = \"$RELEASE_VERSION\"" ./deploy/charts/external-secrets/Chart.yaml
  123. yq e -i ".appVersion = \"$RELEASE_VERSION\"" ./deploy/charts/external-secrets/Chart.yaml
  124. make manifests
  125. - name: Sign promoted image
  126. id: sign
  127. uses: ./.github/actions/sign
  128. with:
  129. image-name: ${{ env.IMAGE_NAME }}
  130. image-tag: ${{ env.RELEASE_TAG }}
  131. - name: Update Release
  132. uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe # v2.6.1
  133. with:
  134. tag_name: ${{ github.event.inputs.version }}
  135. files: |
  136. provenance.${{ env.RELEASE_TAG }}.intoto.jsonl
  137. sbom.${{ env.RELEASE_TAG }}.spdx.json
  138. bin/deploy/manifests/external-secrets.yaml
  139. env:
  140. GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"