Skip to content

Instantly share code, notes, and snippets.

@ichenhe
Created May 9, 2022 05:09
Show Gist options
  • Save ichenhe/aafe3db3178e73ead571f502bcb9e92a to your computer and use it in GitHub Desktop.
Save ichenhe/aafe3db3178e73ead571f502bcb9e92a to your computer and use it in GitHub Desktop.
Extract tag in github actions
# !! restriction: trigger must be push:tags !!
name: Demo
on:
push:
tags:
- v[0-9]+*
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/demo
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# key step
# after this, you can use ${{ steps.tag_out.outputs.tag }}
# to read tag value
- name: Set tag output
id: tag_out
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Docker Login
uses: docker/login-action@v2.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker Image
run: docker build .
- name: Push Docker
env:
RELEASE_VERSION: ${{ steps.tag_out.outputs.tag }}
run: |
docker tag ramnew/bpu:1 $REGISTRY/$IMAGE_NAME:${RELEASE_VERSION/v/}
docker tag ramnew/bpu:1 $REGISTRY/$IMAGE_NAME:latest
docker push $REGISTRY/$IMAGE_NAME:${RELEASE_VERSION/v/}
docker push $REGISTRY/$IMAGE_NAME:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment