Giter Club home page Giter Club logo

action-contains-tag's Introduction

GitHub Action: Contains tag

Docker Image CI Code quality CI release GitHub release (latest SemVer)

Simple GitHub action that can be used to check if a commit or branch contains a given tag.

Inputs

tag

Required. The tag you want to check. Also works with ${{ github.ref }} if the workflow was triggered on a tag push.

reference

Required. Branch or commit for which you want to check the tag existence.

verbose

Optional. Log action information to the console. By default true.

frail

Optional. Return an exit code of 1 when tag or reference does not exist. By default true.

Outputs

retval

Boolean specifying whether the reference contained the tag.

tag

The (trimmed) input tag that as used as a input.

linked_commit

The commit that is currently linked to the tag.

reference

The reference that was used as a input.

Example usage

name: Contains tag
on:
  push:
    branch: "main"
jobs:
  create-tag:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: rickstaa/action-contains-tag@v1
        id: contains_tag
        with:
          reference: "main"
          tag: "Latest"
      - run: |
          if [[ ${{ steps.contains_tag.outputs.retval }} != 'true' ]]; then
            echo "Branch/commit did contain the tag."
          else
            echo "Branch/commit did not contain the tag."
          fi

Use case

I created this action since I wanted to combine the tag and push to branch filters. I send a feature request to the GitHub support. Until this feature is released, this action can be used as a temporary workaround. The recipe below ensures that a workflow is only triggered when a tag is pushed to the master branch.

name: Github tag test
on:
  push:
    tags:
      - "v*.*.*"
jobs:
  on-main-branch-check:
    runs-on: ubuntu-latest
    outputs:
      on_main: ${{ steps.contains_tag.outputs.retval }}
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: rickstaa/action-contains-tag@v1
        id: contains_tag
        with:
          reference: "main"
          tag: "${{ github.ref }}"
  tag-on-main-job:
    runs-on: ubuntu-latest
    needs: on-main-branch-check
    if: ${{ needs.on-main-branch-check.outputs.on_main == 'true' }}
    steps:
      - run: echo "Tag was pushed to main."
      - run: echo ${{needs.on-main-branch-check.outputs.on_main}}
  tag-not-on-main-job:
    runs-on: ubuntu-latest
    needs: on-main-branch-check
    if: ${{ needs.on-main-branch-check.outputs.on_main != 'true' }}
    steps:
      - run: echo "Tag was not pushed to main."
      - run: echo ${{needs.on-main-branch-check.outputs.on_main}}

Limitations & Gotchas

When use Checkout@v3, only a single commit is fetched by default. You must therefore set the right fetch_depth in order to be able to access all the tags.

Contributing

Feel free to open an issue if you have ideas on how to make this GitHub action better or if you want to report a bug! All contributions are welcome. ๐Ÿš€ Please consult the contribution guidelines for more information.

action-contains-tag's People

Contributors

renovate-bot avatar renovate[bot] avatar rickstaa avatar snvector avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

action-contains-tag's Issues

[UPSTREAM_BUG] Error: fatal: not in a git directory

Git recently pushed a change in response to a cve that causes git commands to fail if the parent directory changes ownership from the current directory. You may see errors like:

/usr/bin/git remote add origin https://github.com/wez/wezterm
Error: fatal: unsafe repository ('/__w/wezterm/wezterm' is owned by someone else)

or

Run rickstaa/action-create-tag@v1
  with:
    tag: latest_release
    force_push_tag: true
    commit_sha: xxxx
    github_token: ***
/usr/bin/docker run --name xxx --label xxx --workdir /github/workspace --rm -e INPUT_TAG -e INPUT_FORCE_PUSH_TAG -e INPUT_COMMIT_SHA -e INPUT_GITHUB_TOKEN -e INPUT_MESSAGE -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME -e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e GITHUB_STEP_SUMMARY -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/xxx":"/github/workspace" xxx:xxx
fatal: not in a git directory

The Github Team gave an official statement and work-around at actions/checkout#766. Until GitHub has applied a fix to the action ecosystem, the workaround in #8 will be used. I will remove this workaround after the bug has been fixed upstream. I will keep this issue open to discuss problems while the workaround is used.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

dockerfile
Dockerfile
  • alpine 3.19
github-actions
.github/workflows/code_quality.yml
  • actions/checkout v4
  • haya14busa/action-cond v1
  • reviewdog/action-shellcheck v1
  • actions/checkout v4
  • haya14busa/action-cond v1
  • reviewdog/action-hadolint v1
  • actions/checkout v4
  • reviewdog/action-misspell v1
  • actions/checkout v4
  • reviewdog/action-alex v1
.github/workflows/dockerimage.yml
  • actions/checkout v4
.github/workflows/release.yml
  • actions/checkout v4
  • haya14busa/action-bumpr v1
  • haya14busa/action-update-semver v1
  • haya14busa/action-cond v1
  • actions/create-release v1
  • actions/checkout v4
  • haya14busa/action-bumpr v1
.github/workflows/test.yml
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4

  • Check this box to trigger a request for Renovate to run again on this repository

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.