name: Draft GitHub Release on: push: tags: - 'v*.*.*' workflow_dispatch: inputs: tag: description: 'Tag to release, for example v0.1.1' required: true type: string permissions: contents: write env: FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true jobs: release: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Resolve tag id: vars run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then echo "tag=${{ inputs.tag }}" >> "$GITHUB_OUTPUT" else echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT" fi - name: Build release notes from CHANGELOG shell: bash run: | tag="${{ steps.vars.outputs.tag }}" version="${tag#v}" awk -v version="$version" ' index($0, "## [" version "]") == 1 { capture=1; next } capture && index($0, "## [") == 1 { exit } capture { print } ' CHANGELOG.md > /tmp/release-notes.md if [ ! -s /tmp/release-notes.md ]; then printf 'Release %s\n' "$tag" > /tmp/release-notes.md fi - name: Create or update release env: GH_TOKEN: ${{ github.token }} run: | tag="${{ steps.vars.outputs.tag }}" assets=(docker-compose.example.yml .env.example) existing=() for asset in "${assets[@]}"; do [ -f "$asset" ] && existing+=("$asset") done if gh release view "$tag" >/dev/null 2>&1; then gh release edit "$tag" --title "$tag" --notes-file /tmp/release-notes.md if [ ${#existing[@]} -gt 0 ]; then gh release upload "$tag" "${existing[@]}" --clobber fi else gh release create "$tag" "${existing[@]}" --title "$tag" --notes-file /tmp/release-notes.md fi