release.yml 5.5 KB

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