Skip to content
Snippets Groups Projects
github_release.yml 4.19 KiB
Newer Older
name: Create GitHub Release after GitLab tag mirror

on:
  push:
    tags:
    steps:
      # GET LATEST CODE
      - name: Checkout latest code
        uses: actions/checkout@master
        with:
          fetch-depth: 0

      # EXTRACT TAG FROM PUSH
      - name: Get tag
        id: tag
        uses: dawidd6/action-get-tag@v1
      - name: Use tag
        run: echo ${{steps.tag.outputs.tag}}

      # GET RELEASE INFO
      - name: Get Release Info
        run: |
          curl --header \
          'PRIVATE-TOKEN: ${{ secrets.GITLAB_TOKEN }}' \
          'https://git.griefed.de/api/v4/projects/95/releases/${{steps.tag.outputs.tag}}' >> ./version.json

      # GET DESCRIPTION
      - name: Extract version changelog
        uses: sergeysova/jq-action@v2
        id: description
          cmd: "jq .description version.json -r | sed -e 's/\\n/\\n/g' > description.txt"
      # BUILD PROJECT AND PUBLISH TO PACKAGES
      - name: Set up JDK 8
        uses: actions/setup-java@v3
      - name: Grant execute permission for gradlew
        run: chmod +x gradlew
      - name: Publish to GitHub Packages
        env:
          GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          ./gradlew -Pversion=${{steps.tag.outputs.tag}} build --info --full-stacktrace -x test
      # GENERATE RELEASE
      - name: Create Release
        id: create_release
        uses: softprops/action-gh-release@v1
          token: ${{ secrets.GITHUB_TOKEN }}
          tag_name: ${{steps.tag.outputs.tag}}
          name: Release ${{steps.tag.outputs.tag}}
          body_path: description.txt
          draft: false
          prerelease: false
          fail_on_unmatched_files: false
          files: |
            build/libs/ServerPackCreatorExampleAddon-${{ needs.release.outputs.newtag }}.jar
            build/libs/ServerPackCreatorExampleAddon-${{ needs.release.outputs.newtag }}-sources.jar
            build/libs/ServerPackCreatorExampleAddon-${{ needs.release.outputs.newtag }}-javadoc.jar
      # PUBLISH ARTIFACTS
      - uses: actions/upload-artifact@v3
          name: build-artifacts-gradle
          path: |
            build
          if-no-files-found: warn # 'warn' or 'ignore' are also available, defaults to `warn`
      # ANNOUNCE NEW VERSION
      - name: Get current date
        id: date
        run: echo "::set-output name=today::$(date +'%Y-%m-%dT%H:%M:%S')"
      - name: Post WebHook Message
        run: |
          curl -L --output ./discord.sh https://raw.githubusercontent.com/ChaoticWeg/discord.sh/master/discord.sh
          chmod a+x ./discord.sh
          ./discord.sh \
            --webhook-url="${{ secrets.WEBHOOK_URL }}" \
            --username "$GITHUB_REPOSITORY" \
            --avatar "https://i.griefed.de/images/2020/11/18/Prosper_Docker_300x300.png" \
            --text "There's been a new release for $GITHUB_REPOSITORY. The new version is ${{steps.tag.outputs.tag}} and is available at <$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/${{steps.tag.outputs.tag}}>" \
            --title "New $GITHUB_REPOSITORY Release" \
            --description "There's been a new release for $GITHUB_REPOSITORY. The new version is ${{steps.tag.outputs.tag}} and is available at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/${{steps.tag.outputs.tag}}" \
            --color "0xC0FFEE" \
            --url "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/${{steps.tag.outputs.tag}}" \
            --author "Griefed" \
            --author-url "$GITHUB_SERVER_URL/Griefed" \
            --author-icon "https://i.griefed.de/images/2022/01/21/sam_1500x1500.th.jpg" \
            --thumbnail "https://i.griefed.de/images/2022/09/15/icon.png" \
            --field "Author;[Griefed]($GITHUB_SERVER_URL/Griefed)" \
            --field "Platform;[GitHub]($GITHUB_SERVER_URL)" \
            --footer "Released at ${{ steps.date.outputs.today }}" \
            --footer-icon "https://i.griefed.de/images/2022/01/21/start_generation.png"