From 266e745a7dd970299a7029eb15957afc6b47240d Mon Sep 17 00:00:00 2001 From: Dmitrii Suchkov Date: Fri, 11 Sep 2026 08:52:27 +0100 Subject: [PATCH] use composite instead of docker --- .github/workflows/main.yml | 5 +++-- Dockerfile | 9 --------- README.md | 18 +++++++++++++----- action.yml | 23 ++++++++++++++++++++--- entrypoint.sh | 15 --------------- 5 files changed, 36 insertions(+), 34 deletions(-) delete mode 100644 Dockerfile delete mode 100755 entrypoint.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 198e26a..8ab1219 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,8 +5,9 @@ jobs: runs-on: ubuntu-latest name: Test action steps: + - uses: actions/checkout@v7 - name: Use action id: get-branch - uses: codio/get-branch-name-github-action@master - - name: Echo outpus + uses: ./ + - name: Echo outputs run: echo "name=${{ steps.get-branch.outputs.branch }} - tag=${{ steps.get-branch.outputs.tag }}" diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 636c5d4..0000000 --- a/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -# Container image that runs your code -FROM alpine:3.10 -RUN apk add --no-cache --upgrade bash - -# Copies your code file from your action repository to the filesystem path `/` of the container -COPY entrypoint.sh /entrypoint.sh - -# Code file to execute when the docker container starts up (`entrypoint.sh`) -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index e2bd198..4ec7890 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,23 @@ # Get-Branch-Name Github Action -This action outputs the current branch name and corresponding tag. +This action outputs the current branch name and corresponding tag. Composite action: one `bash` step, no container build per run and no Node runtime to deprecate. ## Outputs + ### `branch` -The current branch name. + +The current branch name — `GITHUB_REF` with the `refs/heads/` prefix removed. Refs that are not branches (tags, pull requests) come through unchanged, e.g. `refs/tags/v1`. ### `tag` -The corresponding tag name. If `master` -> `latest`, `branch-name` for the others. + +`master` on the master branch, `latest` when the ref is a tag, empty otherwise. ## Example usage + +```yaml +- name: Get Current Branch + id: get-branch + uses: codio/get-branch-name-github-action@v2 + +- run: echo "${{ steps.get-branch.outputs.branch }} / ${{ steps.get-branch.outputs.tag }}" ``` -uses: ypicard/get-branch-name-github-action@v1 -``` \ No newline at end of file diff --git a/action.yml b/action.yml index e38f7af..a7ca239 100644 --- a/action.yml +++ b/action.yml @@ -2,13 +2,30 @@ name: 'Get Branch Name and Tag' description: 'Get current branch name and corresponding branch tag if needed.' branding: - icon: 'activity' + icon: 'activity' color: 'white' outputs: branch: description: 'Current branch name' + value: ${{ steps.get-branch.outputs.branch }} tag: description: 'Corresponding branch tag' + value: ${{ steps.get-branch.outputs.tag }} runs: - using: 'docker' - image: 'Dockerfile' \ No newline at end of file + using: composite + steps: + - id: get-branch + shell: bash + run: | + set -euo pipefail + branch="${GITHUB_REF#refs/heads/}" + tag='' + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then + tag='latest' + elif [[ "${branch}" == 'master' ]]; then + tag='master' + fi + { + echo "branch=${branch}" + echo "tag=${tag}" + } >> "${GITHUB_OUTPUT}" diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 7f8e61b..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -declare -A TAGS_MAP -TAGS_MAP=( ["master"]="master") - -BRANCH=$(echo ${GITHUB_REF} | sed -e "s/refs\/heads\///g") -TAG=${TAGS_MAP[$BRANCH]} - -# if contains /refs/tags/ -if [ $(echo ${GITHUB_REF} | sed -e "s/refs\/tags\///g") != ${GITHUB_REF} ]; then - TAG="latest" -fi; - -echo "branch=${BRANCH}" >> ${GITHUB_OUTPUT} -echo "tag=${TAG}" >> ${GITHUB_OUTPUT}