Created
December 2, 2019 09:11
-
-
Save crazy-max/f347632c53c81271906697bdb40e8074 to your computer and use it in GitHub Desktop.
Workflow to release a GitHub Action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: release | |
on: | |
push: | |
branches-ignore: | |
- '**' | |
tags: | |
- 'v*.*.*' | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- | |
# https://github.com/actions/checkout | |
name: Checkout | |
uses: actions/checkout@v1 | |
- | |
name: Prepare | |
id: prepare | |
run: | | |
TAG=${GITHUB_REF#refs/tags/} | |
MINOR=${TAG%.*} | |
MAJOR=${MINOR%.*} | |
echo ::set-output name=tag_name::${TAG} | |
echo ::set-output name=minor_tag::${MINOR} | |
echo ::set-output name=major_tag::${MAJOR} | |
echo ::set-output name=major_exists::$(git show-ref origin/releases/${MAJOR}) | |
- | |
name: Set up Git | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config user.name "${GITHUB_ACTOR}" | |
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" | |
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git | |
- | |
name: Checkout releases/${{ steps.prepare.outputs.major_tag }} branch | |
run: | | |
git checkout -B releases/${{ steps.prepare.outputs.major_tag }} | |
if [ -n "${{ steps.prepare.outputs.major_exists }}" ]; then | |
git branch --set-upstream-to=origin/releases/${{ steps.prepare.outputs.major_tag }} releases/${{ steps.prepare.outputs.major_tag }} | |
fi | |
- | |
# https://github.com/actions/setup-node | |
name: Set up Node | |
uses: actions/setup-node@v1 | |
- | |
name: NPM production deps | |
run: | | |
rm -rf node_modules | |
sed -i '/node_modules/d' .gitignore | |
npm install --production | |
- | |
name: Commit and push changes | |
run: | | |
git add --all | |
git status --short -uno | |
git commit -m 'Release ${{ steps.prepare.outputs.tag_name }}' | |
git show --stat-count=10 HEAD | |
git push -f origin releases/${{ steps.prepare.outputs.major_tag }} | |
- | |
name: Update ${{ steps.prepare.outputs.minor_tag }} tag | |
run: | | |
git push origin :refs/tags/${{ steps.prepare.outputs.minor_tag }} | |
git tag -fa ${{ steps.prepare.outputs.minor_tag }} -m "Release ${{ steps.prepare.outputs.tag_name }}" | |
git push origin ${{ steps.prepare.outputs.minor_tag }} | |
- | |
name: Update ${{ steps.prepare.outputs.major_tag }} tag | |
run: | | |
git push origin :refs/tags/${{ steps.prepare.outputs.major_tag }} | |
git tag -fa ${{ steps.prepare.outputs.major_tag }} -m "Release ${{ steps.prepare.outputs.tag_name }}" | |
git push origin ${{ steps.prepare.outputs.major_tag }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Workflow to release a GitHub Action
This workflow will automate the creation of branches and tags when you release your GitHub Action according to the recommendations of GitHub.
It will be triggered on tag creation with this specific pattern:
v*.*.*
. This pattern is important because we want to take care of major, minor version of your GitHub Action to create specific branches and tags.Let's take an example with the ghaction-github-pages action. I have already uploaded this workflow and now I will create a new release
v1.2.5
for this action:Here's what the steps look like:
v1
and minorv1.2
fromGITHUB_REF
env var (tag name)releases/v1
exists and create it if not.releases/v1
v1.2
and majorv1
Here's what your Releases page will looks like: