name: release-please on: push: branches: - main permissions: contents: write pull-requests: write jobs: release-please: runs-on: ubuntu-latest steps: - uses: actions/create-github-app-token@v2 id: app-token with: app-id: ${{ secrets.RELEASE_PLEASE_APP_ID }} private-key: ${{ secrets.RELEASE_PLEASE_APP_KEY }} - id: rp uses: googleapis/release-please-action@v4 with: config-file: release-please-config.json manifest-file: .release-please-manifest.json token: ${{ steps.app-token.outputs.token }} - name: Sync Chart.yaml appVersion on release PR if: ${{ steps.rp.outputs.prs_created == 'true' }} env: GH_TOKEN: ${{ steps.app-token.outputs.token }} PRS: ${{ steps.rp.outputs.prs }} REPO: ${{ github.repository }} run: | set -euo pipefail echo "$PRS" | jq -c '.[]' | while read -r pr; do branch=$(echo "$pr" | jq -r '.headBranchName') workdir=$(mktemp -d) git clone --branch "$branch" --depth 1 \ "https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git" "$workdir" cd "$workdir" git config user.email "garage-ui-release-bot[bot]@users.noreply.github.com" git config user.name "garage-ui-release-bot[bot]" version=$(jq -r '."."' .release-please-manifest.json) target="v${version}" sed -i -E "s|^appVersion:.*|appVersion: ${target}|" helm/garage-ui/Chart.yaml if ! git diff --quiet helm/garage-ui/Chart.yaml; then git add helm/garage-ui/Chart.yaml git commit -m "chore: sync Chart.yaml appVersion to ${target}" git push origin "$branch" fi cd - rm -rf "$workdir" done - name: Cut chart patch when backend released without chart if: ${{ steps.rp.outputs.releases_created == 'true' }} env: GH_TOKEN: ${{ steps.app-token.outputs.token }} REPO: ${{ github.repository }} BACKEND_RELEASED: ${{ steps.rp.outputs.release_created }} CHART_RELEASED: ${{ steps.rp.outputs['helm/garage-ui--release_created'] }} BACKEND_TAG: ${{ steps.rp.outputs.tag_name }} BACKEND_VERSION: ${{ steps.rp.outputs.version }} run: | set -euo pipefail if [ "$BACKEND_RELEASED" != "true" ] || [ "$CHART_RELEASED" = "true" ]; then echo "Backend not released, or chart already released this cycle. Nothing to do." exit 0 fi workdir=$(mktemp -d) git clone \ "https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git" "$workdir" cd "$workdir" git config user.email "garage-ui-release-bot[bot]@users.noreply.github.com" git config user.name "garage-ui-release-bot[bot]" chart_old=$(jq -r '."helm/garage-ui"' .release-please-manifest.json) chart_new=$(echo "$chart_old" | awk -F. '{printf "%d.%d.%d", $1, $2, $3+1}') chart_tag="garage-ui-chart-v${chart_new}" jq --arg v "$chart_new" '."helm/garage-ui" = $v' \ .release-please-manifest.json > .release-please-manifest.json.tmp mv .release-please-manifest.json.tmp .release-please-manifest.json sed -i -E "s|^version:.*|version: ${chart_new}|" helm/garage-ui/Chart.yaml sed -i -E "s|^appVersion:.*|appVersion: ${BACKEND_TAG}|" helm/garage-ui/Chart.yaml today=$(date -u +%Y-%m-%d) compare_url="https://github.com/${REPO}/compare/garage-ui-chart-v${chart_old}...${chart_tag}" entry=$(printf '## [%s](%s) (%s)\n\n\n### Miscellaneous Chores\n\n* sync chart appVersion to %s\n' \ "$chart_new" "$compare_url" "$today" "$BACKEND_TAG") awk -v entry="$entry" 'NR==1 && /^# Changelog/ { print; print ""; print entry; next } { print }' \ helm/garage-ui/CHANGELOG.md > helm/garage-ui/CHANGELOG.md.tmp mv helm/garage-ui/CHANGELOG.md.tmp helm/garage-ui/CHANGELOG.md git add .release-please-manifest.json helm/garage-ui/Chart.yaml helm/garage-ui/CHANGELOG.md git commit -m "chore: bump chart to ${chart_new} for backend ${BACKEND_TAG}" git push origin main git tag "$chart_tag" git push origin "$chart_tag" gh release create "$chart_tag" \ --repo "$REPO" \ --title "$chart_tag" \ --notes "Chart patch synced to backend ${BACKEND_TAG}. No chart template changes."