Git Product home page Git Product logo

Comments (4)

OneCricketeer avatar OneCricketeer commented on August 19, 2024

e.g.

+const include= new RegExp('^build-me');
+const exclude= new RegExp('^forget-me');

const createTags = () => {
  core.info('Creating Docker image tags...');
  const { sha } = context;
  const addLatest = core.getInput('addLatest') === 'true';
  const ref = context.ref.toLowerCase();
  const shortSha = sha.substring(0, 7);
  const dockerTags = [];

  if (isGitHubTag(ref)) {
    // If GitHub tag exists, use it as the Docker tag
    const tag = ref.replace('refs/tags/', '');
+   if (include.test(tag) && !exclude.test(tag)) {
+     dockerTags.push(tag);
+   }
  } else if (isBranch(ref)) {
    // If we're not building a tag, use branch-prefix-{GIT_SHORT_SHA) as the Docker tag
    // refs/heads/jira-123/feature/something
    const branchName = ref.replace('refs/heads/', '');
    const safeBranchName = branchName
      .replace(/[^\w.-]+/g, '-')
      .replace(/^[^\w]+/, '')
      .substring(0, 120);
    const tag = `${safeBranchName}-${shortSha}`;
+   if (include.test(safeBranchName) && !exclude.test(safeBranchName)) {
+     dockerTags.push(tag);
+   }
  } else {
    core.setFailed(
      'Unsupported GitHub event - only supports push https://help.github.com/en/articles/events-that-trigger-workflows#push-event-push'
    );
  }

  if (addLatest) {
    dockerTags.push('latest');
  }

  core.info(`Docker tags created: ${dockerTags}`);
  return dockerTags;
};

from docker-build-push.

mr-smithers-excellent avatar mr-smithers-excellent commented on August 19, 2024

Hi @OneCricketeer - thanks for the suggestion. Can you talk a bit more about the use case here?

from docker-build-push.

OneCricketeer avatar OneCricketeer commented on August 19, 2024

Well, say we want to push all tags that match a certain pattern rather than hardcode and continually update that list?

from docker-build-push.

mr-smithers-excellent avatar mr-smithers-excellent commented on August 19, 2024

This is a bit of an atypical use case. For now, I'd suggest you apply any regex logic in a preceding step, generating your tags as an environment variable to be applied via the tags input of this action.

from docker-build-push.

Related Issues (20)

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.