Skip to content

Instantly share code, notes, and snippets.

@tswfi
Created February 3, 2021 15:20
Show Gist options
  • Save tswfi/b7ac247cd337aa85f76d29f68ede779f to your computer and use it in GitHub Desktop.
Save tswfi/b7ac247cd337aa85f76d29f68ede779f to your computer and use it in GitHub Desktop.
name: TagToRelease
on:
push:
tags:
- 'v*'
jobs:
build:
name: Process
runs-on: ubuntu-latest
steps:
# catch the repo name
- name: Get repo name
id: get_reponame
run: echo ::set-output name=REPONAME::${{ github.event.repository.name }}
# parse v1.x.x from the tag ref to be used later
# https://github.community/t/how-to-get-just-the-tag-name/16241/5
- name: Get Version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
# checkout the code, defaults to correct tags etc automatically
# https://github.com/actions/checkout
- name: Checkout
uses: actions/checkout@v1
# create zip package
- name: Create zip package
run: |
mkdir -p release
rsync -arv --exclude='release' --exclude='.git/' --exclude='.github/' --exclude='.gitignore' . ./release/${{ steps.get_reponame.outputs.REPONAME }}/
cd release
zip -r ${{ steps.get_reponame.outputs.REPONAME }}-${{ steps.get_version.outputs.VERSION }}.zip ${{ steps.get_reponame.outputs.REPONAME }}
# create new release
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ steps.get_version.outputs.VERSION }}
draft: false
prerelease: false
# upload the zip package to the release
- name: Upload asset to release
id: upload_asset_to_release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`.
# See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./release/${{ steps.get_reponame.outputs.REPONAME }}-${{ steps.get_version.outputs.VERSION }}.zip
asset_name: ${{ steps.get_reponame.outputs.REPONAME }}-${{ steps.get_version.outputs.VERSION }}.zip
asset_content_type: application/zip
@tswfi
Copy link
Author

tswfi commented Feb 3, 2021

Usage:

git checkout main
git commit -a -m "Upping version number to v1.x.x"
git push
git tag v1.x.x
git push origin tags

The repo name must match the module name.

Creates zip packages in format: reponame-v1.x.x.zip in the release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment