Hion Coding - Blogs share everything
  • HOME
  • ABOUT
  • POSTS
  • CONTACT
  • TOOLS
    CÂU HỎI VÕ ĐÀI TỐI THƯỢNG CONVERT IMAGE TO WEBP
Create Release in Github action - How to do it?

Create Release in Github action - How to do it?

Hion Coding - Blogs share everything
Admin Hion Coding Blogs vochilong.work@gmail.com
26th April 2024

Git/Github

Create Release in Github action - How to do it?

Automating the release process in software development can help improve project performance and reliability. GitHub Actions is a powerful tool that allows automating tasks such as creating release tags, building source code, and deploying. This article will show you how to create automatic release tags using GitHub Actions for the HionCoding website, with clear steps and illustrations with example code.

 

1: Introducing GitHub Actions and Release Tags

GitHub Actions is a feature of GitHub that allows you to automate tasks using YAML files to define workflows. Release tags are a way to mark stable versions of a project, for easy future reference, and are an important step in the software release process.


2: Config GitHub Actions

To create a GitHub Action to automate release tag generation, you need to create a YAML file in your project's .github/workflows directory. This YAML file defines the steps required to create a release tag when a specific event occurs.
Below I have 3 ways to create a release:

name: Create Release Tag

on:
  push:
    branches:
      - main

jobs:
  create_tag:
    runs-on: ubuntu-latest
    
    permissions:
      id-token: write
      contents: write

    steps:
      - name: Checkout Repository
        uses: actions/checkout@v3

      - name: Create tag name
        id: create_tag_name
        run: |
          echo "tag_name=v1.3.3" >> $GITHUB_OUTPUT
          echo "tag_name_gh=v1.3.4" >> $GITHUB_OUTPUT
          echo "tag_name_api=v1.3.5" >> $GITHUB_OUTPUT
        

      - name: Create New Tag
        run: |
          echo "${{ steps.create_tag_name.outputs.tag_name }}"
          tag_name="${{ steps.create_tag_name.outputs.tag_name }}"
          git tag $tag_name
          git push origin $tag_name

      - name: Create Release by actions/create-release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: "${{ steps.create_tag_name.outputs.tag_name }}"
          release_name: Release "${{ steps.create_tag_name.outputs.tag_name }}"
          body: |
            Changes in this Release
            - First Change
            - Second Change
          draft: false
          prerelease: false

     # By GH
      - name: Install GitHub CLI
        run: |
          sudo apt update
          sudo apt install -y gh

      - name: Create GitHub Release by GH
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          tag_name="${{ steps.create_tag_name.outputs.tag_name_gh }}"
          gh release create $tag_name -t "Release $tag_name" -n "Description for Release $tag_name"

      - name: Create GitHub Release with API
        run: |
          tag_name="${{ steps.create_tag_name.outputs.tag_name_api }}"
          curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
            -d '{
                "tag_name": "'$tag_name'",
                "target_commitish": "main",
                "name": "Release '$tag_name'",
                "body": "Description for release '$tag_name'",
                "draft": false,
                "prerelease": false
              }' \
            https://api.github.com/repos/${{ github.repository }}/releases

Note:

  • draft: false: If you want to create a draft release, set it to true.
  • prerelease: false: Set to true if this is a prerelease version.

Result:

Conclusion:

By using GitHub Actions, you can automate the release tag generation process, helping to increase efficiency and reliability in software development. The example code in this article will get you started, but you can customize to your project's specific needs. Wishing you success in implementing an automated release process and enjoying its benefits for your project.

If you need further assistance or have other questions about GitHub Actions, join the GitHub community or refer to the official documentation to learn more about advanced features and how to apply them to your project.

 

HionCoding! Thank you!


Tạo Release trong Github action - How to do it?

26th April 2024

Tạo Release trong Github action - How to do it?

Git/Github

Auto deployment với GitHub Actions cho cPanel hoặc VPS 🚀

31st March 2024

Auto deployment với GitHub Actions cho cPanel hoặc VPS 🚀

Git/Github

Auto deployment with GitHub Actions for cPanel or VPS 🚀

31st March 2024

Auto deployment with GitHub Actions for cPanel or VPS 🚀

Git/Github

Scheduling your GitHub Actions cron-style

9th April 2024

Scheduling your GitHub Actions cron-style

Git/Github

Hion Coding - Blogs share everything


© 2025 Hion Coding DMCA.com Protection Status