Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
/ docker-tag-exists Public archive
generated from actions/typescript-action

Custom GitHub Action to check if a tag exists on a Docker Repository

License

Notifications You must be signed in to change notification settings

hipcamp/docker-tag-exists

Repository files navigation

Usage

Pre-requisites

Create a workflow .yml file in your repositories .github/workflows directory. An example workflow is available below. For more information, reference the GitHub Help Documentation for Creating a workflow file.

Inputs

  • username - dockerhub username OPTIONAL
  • password - dockerhub password OPTIONAL
  • image - docker image
  • tag - docker image tag

Outputs

  • tag-exists - if that tag exists or not

Example Workflow

name: Use Self-Hosted Runners
on: push
jobs:
  check-for-existing-docker-image:
    name: Check Docker for Matching Tag
    runs-on: ubuntu-latest
    needs: start-self-hosted-runners
    outputs:
      tag-exists: ${{steps.check-docker.outputs.tag-exists}}
    steps:
      - id: check-docker
        name: Check Docker for Tag
        uses: hipcamp/docker-tag-exists@v1
        with:
          image: library/ubuntu
          tag: 20.04
  build-and-deploy-docker-image:
    name: Build and Deploy Docker Image
    runs-on: ubuntu-latest
    needs: check-for-existing-docker-image
    if: needs.check-for-existing-docker-image.outputs.tag-exists != 'true'
    steps:
      - run: echo "Build and Deploy Docker Image"

How to Contribute

First, you'll need to have a reasonably modern version of node handy. This won't work with versions older than 9, for instance.

Install the dependencies

$ npm install

Build the typescript and package it for distribution

$ npm run build && npm run package

Run the tests ✔️

$ npm test

 PASS  ./index.test.js
  ✓ throws invalid number (3ms)
  ✓ wait 500 ms (504ms)
  ✓ test runs (95ms)

...

Change action.yml

The action.yml contains defines the inputs and output for your action.

Update the action.yml with your name, description, inputs and outputs for your action.

See the documentation

Change the Code

Most toolkit and CI/CD operations involve async operations so the action is run in an async function.

import * as core from '@actions/core';
...

async function run() {
  try { 
      ...
  } 
  catch (error) {
    core.setFailed(error.message);
  }
}

run()

See the toolkit documentation for the various packages.

Publish to a Distribution Branch

Actions are run from GitHub repos so we will checkin the packed dist folder.

$ npm run all
$ git add -A
$ git commit -m "your commit message"
$ git tag v[version from package.json]
$ git push origin v[version from package.json]

Your action is now published! 🚀

See the versioning documentation

About

Custom GitHub Action to check if a tag exists on a Docker Repository

Resources

License

Stars

Watchers

Forks

Packages

No packages published