1name: Release
2
3on:
4  push:
5    tags:
6      - 'v*'
7
8jobs:
9  release:
10    runs-on: ubuntu-latest
11    steps:
12      - name: Checkout code
13        uses: actions/checkout@v2
14        with:
15          fetch-depth: 0
16
17      - name: Set Tag as Filename
18        id: tag_name
19        run: echo "TAG_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
20
21      - name: Create ZIP file
22        run: zip -r "${{ env.TAG_NAME }}.zip" .
23
24      - name: Generate Changelog
25        id: generate_changelog
26        run: |
27          # Find the most recent tag before the current one
28          PREV_TAG=$(git describe --tags --abbrev=0 HEAD^)
29
30          # Create a new CHANGELOG.md file with headers
31          echo -e "# Changelog\n" > CHANGELOG.md
32
33          # List commit messages between the previous tag and current HEAD
34          git log ${PREV_TAG}..HEAD --pretty=format:"* %s" >> CHANGELOG.md
35
36          # List unique contributors for these commits
37          echo -e "\n\n# Contributors\n" >> CHANGELOG.md
38          git log ${PREV_TAG}..HEAD --format='%aN' | sort -u | awk '{print "* " $0}' >> CHANGELOG.md
39
40      - name: Create Release
41        id: create_release
42        uses: actions/create-release@v1
43        env:
44          GITHUB_TOKEN: ${{ secrets.GH_PAT }}
45        with:
46          tag_name: ${{ github.ref }}
47          release_name: Release ${{ github.ref }}
48          draft: false
49          prerelease: false
50          body_path: ./CHANGELOG.md
51
52      - name: Upload Asset
53        uses: actions/upload-release-asset@v1
54        env:
55          GITHUB_TOKEN: ${{ secrets.GH_PAT }}
56        with:
57          upload_url: ${{ steps.create_release.outputs.upload_url }}
58          asset_path: ./${{ env.TAG_NAME }}.zip
59          asset_name: source.zip
60          asset_content_type: application/zip
61