|
| 1 | +name: Generate Release Notes |
| 2 | + |
| 3 | +on: |
| 4 | + # repository_dispatch: |
| 5 | + # types: [release-published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + published_packages: |
| 9 | + description: 'JSON array of published packages (e.g. [{"name":"@medusajs/medusa","version":"2.13.5"}])' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +jobs: |
| 14 | + create-github-release: |
| 15 | + name: Create GitHub Release |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout Repo |
| 19 | + uses: actions/checkout@v3 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Determine release version |
| 24 | + id: version |
| 25 | + run: | |
| 26 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 27 | + PACKAGES='${{ github.event.inputs.published_packages }}' |
| 28 | + else |
| 29 | + PACKAGES='${{ toJson(github.event.client_payload.published_packages) }}' |
| 30 | + fi |
| 31 | + VERSION=$(echo "$PACKAGES" | jq -r '.[0].version') |
| 32 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 33 | + echo "tag=v$VERSION" >> "$GITHUB_OUTPUT" |
| 34 | +
|
| 35 | + - name: Find previous release tag |
| 36 | + id: previous |
| 37 | + run: | |
| 38 | + CURRENT_TAG="${{ steps.version.outputs.tag }}" |
| 39 | + # Fetch all tags |
| 40 | + git fetch --tags |
| 41 | + # Find the previous stable release tag (exclude pre-releases) |
| 42 | + PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | grep -v "$CURRENT_TAG" | head -1) |
| 43 | + echo "tag=$PREVIOUS_TAG" >> "$GITHUB_OUTPUT" |
| 44 | +
|
| 45 | + - name: Create GitHub Release with auto-generated notes |
| 46 | + env: |
| 47 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + run: | |
| 49 | + TAG="${{ steps.version.outputs.tag }}" |
| 50 | + VERSION="${{ steps.version.outputs.version }}" |
| 51 | + PREVIOUS_TAG="${{ steps.previous.outputs.tag }}" |
| 52 | +
|
| 53 | + ARGS=( |
| 54 | + "$TAG" |
| 55 | + --title "$TAG" |
| 56 | + --generate-notes |
| 57 | + --target "${{ github.sha }}" |
| 58 | + ) |
| 59 | +
|
| 60 | + if [ -n "$PREVIOUS_TAG" ]; then |
| 61 | + ARGS+=(--notes-start-tag "$PREVIOUS_TAG") |
| 62 | + fi |
| 63 | +
|
| 64 | + gh release create "${ARGS[@]}" |
0 commit comments