Git Product home page Git Product logo

readme-download-button-action's Introduction

Readme Download Button Action

GitHub Action workflow configuration for keeping a direct download link of the latest version in your README.md file.

Example

With a single click of the button below, a zip of this repository will start downloading.

Download zip

The URL this button leads to is automatically updated on each release by this workflow.

Basic Usage

This workflow consists mainly of four parts:

Step 1

Add the following snippet within your README.md file anywhere you want the button to appear:

<!-- BEGIN LATEST DOWNLOAD BUTTON -->
<!-- END LATEST DOWNLOAD BUTTON -->

Step 2

Create a workflow by placing the following in a .yml file in your .github/workflows/ directory:

name: "Download Button Action"

on:
  release:
    types:
      - published
  workflow_dispatch:

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Get latest release
        id: get-latest-release
        uses: InsonusK/[email protected]
        with:
          myToken: ${{ github.token }}
          view_top: 1

      - name: Readme Download Button Action
        env:
          GITHUB_USER: "DenverCoder1"
          REPO: "readme-download-button-action"
          FORMAT: "zip"
          VERSION: "${{ steps.get-latest-release.outputs.tag_name }}"
          COLOR: "blue"
          BEGIN_TAG: "<!-- BEGIN LATEST DOWNLOAD BUTTON -->"
          END_TAG: "<!-- END LATEST DOWNLOAD BUTTON -->"
        run: |
          UPDATE=$(cat README.md | perl -0777 -pe 's#(${{ env.BEGIN_TAG }})(?:.|\n)*?(${{ env.END_TAG }})#${1}\n[![Download ${{ env.FORMAT }}](https://custom-icon-badges.demolab.com/badge/-Download-${{ env.COLOR }}?style=for-the-badge&logo=download&logoColor=white "Download ${{ env.FORMAT }}")](https://github.com/${{ env.GITHUB_USER }}/${{ env.REPO }}/archive/${{ env.VERSION }}.${{ env.FORMAT }})\n${2}#g')
          echo "${UPDATE}" > README.md

      - uses: EndBug/add-and-commit@v7
        with:
          message: "docs(readme): Bump download button version to ${{ steps.get-latest-release.outputs.tag_name }}"
          default_author: github_actions
          branch: main

Step 3

Update the variables in the env section of the Readme Download Button Action step to include your username and repo along with any configuration you want as described below in the Options section.

Options

In the Readme Download Button Action step of the workflow, the following environment variables must be set:

Variable Example Description
GITHUB_USER "DenverCoder1" The GitHub username of the user who owns the repository
REPO "readme-download-button-action" The name of the repository
FORMAT "zip", "tar.gz" The file format to download (zip or tar.gz)
VERSION "0.0.1", <tag of latest release>* The tag name of the release
COLOR "blue", "0088AA" The color of the download button (name or hex code)
BEGIN_TAG <!-- BEGIN LATEST DOWNLOAD BUTTON --> The beginning tag of the download button
END_TAG <!-- END LATEST DOWNLOAD BUTTON --> The ending tag of the download button

*For using the latest release, include the get-latest-release step and set VERSION to ${{ steps.get-latest-release.outputs.tag_name }}

Advanced Usage

This workflow can also be used in combination with other actions for automatically creating tags and releases in addition to updating the readme.

For example:

name: "Automatic Release"

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Get latest release
        id: get-latest-release
        uses: InsonusK/[email protected]
        with:
          myToken: ${{ github.token }}
          view_top: 1
      
      - name: Get next tag
        id: next-tag
        run: |
          prev_version=$(echo "${{ steps.get-latest-release.outputs.tag_name }}" | sed -E 's/\..*//g')
          echo "Previous version: $((prev_version))"
          echo "Next version: $((prev_version+1))"
          echo "::set-output name=tag::$((prev_version+1)).0"
          
      - name: Create tag
        uses: tvdias/[email protected]
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          tag: ${{ steps.next-tag.outputs.tag }}

      - uses: fregante/release-with-changelog@v3
        id: release-with-changelog
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          exclude: '^meta|^docs|^document|^lint|^ci|^refactor|readme|workflow|bump|dependencies|yml|^v?\d+\.\d+\.\d+'
          tag: ${{ steps.next-tag.outputs.tag }}
          title: 'Version ${{ steps.next-tag.outputs.tag }}'
          commit-template: '- {hash} {title}'
          skip-on-empty: true
          template: |
            ### Changelog

            {commits}

            {range}
            
      - name: Delete tag if release skipped
        if: ${{ steps.release-with-changelog.outputs.skipped == 'true' }}
        run: |
          git tag -d ${{ steps.next-tag.outputs.tag }}
          git push origin :refs/tags/${{ steps.next-tag.outputs.tag }}

      - name: Readme Download Button Action
        if: ${{ steps.release-with-changelog.outputs.skipped == 'false' }}
        env:
          GITHUB_USER: "DenverCoder1"
          REPO: "readme-download-button-action"
          FORMAT: "zip"
          VERSION: "${{ steps.next-tag.outputs.tag }}"
          COLOR: "blue"
          BEGIN_TAG: "<!-- BEGIN LATEST DOWNLOAD BUTTON -->"
          END_TAG: "<!-- END LATEST DOWNLOAD BUTTON -->"
        run: |
          UPDATE=$(cat README.md | perl -0777 -pe 's#(${{ env.BEGIN_TAG }})(?:.|\n)*?(${{ env.END_TAG }})#${1}\n[![Download ${{ env.FORMAT }}](https://custom-icon-badges.demolab.com/badge/-Download-${{ env.COLOR }}?style=for-the-badge&logo=download&logoColor=white "Download ${{ env.FORMAT }}")](https://github.com/${{ env.GITHUB_USER }}/${{ env.REPO }}/archive/${{ env.VERSION }}.${{ env.FORMAT }})\n${2}#g')
          echo "${UPDATE}" > README.md

      - uses: EndBug/add-and-commit@v7
        if: ${{ steps.release-with-changelog.outputs.skipped == 'false' }}
        with:
          message: 'docs: Bump version to ${{ steps.next-tag.outputs.tag }}'
          default_author: github_actions

License

This work is under an MIT license

Support

If you like this project, give it a โญ and share it with friends!

readme-download-button-action's People

Contributors

denvercoder1 avatar github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.