Skip to content
align-left

GitHub Action

Add-header

v1.1.6 Latest version

Add-header

align-left

Add-header

Intelligently add a header to any file within you repo

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Add-header

uses: Minituff/[email protected]

Learn more about this action in Minituff/add-header-action

Choose a version

Add header-action

GitHub Marketplace CI Status codecov

Intelligently add a header to any file within your repo.

Header examples

------ Expand Me ------

This action can support any UTF-8 file type.

Bash

#!/usr/bin/env bash

# SUPER SECRET CONFIDENTIAL 
# [2023] - [Infinity and Beyond] ACME Inc 
# All Rights Reserved. 

hello-world() {
    echo "Hello world"
}

Javascript

// SUPER SECRET CONFIDENTIAL 
// [2023] - [Infinity and Beyond] ACME Inc 
// All Rights Reserved. 

function helloWorld() {
    console.log("Hello world")
}

HTML

<!DOCTYPE html>

<!-- SUPER SECRET CONFIDENTIAL -->
<!-- [2023] - [Infinity and Beyond] ACME Inc -->
<!-- All Rights Reserved. -->

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" href="style.css" type="text/css">
</head>

And many more.

Usage

This action is ready to go out of the box. To change the header, see the Customization section.

name: Add header

jobs:
  build:
    name: Add headers
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
      with:
        token: ${{ secrets.PAT }} # (only needed for private repos)
    
    - name: Add header action step
      uses: minituff/add-header-action@v1
      with: # All arguments are optional, see the defaults below
        dry-run: false # Don't make any changes, but log what *would* change.
        verbose: false # Extra logging to help you debug.
        file-name: .headerrc.yml # The name of your settings file.
      env:
        FORCE_COLOR: "1" # Optional: Shows color output in GitHub console.

    - name: Commit and Push changes back to repo
      uses: stefanzweifel/git-auto-commit-action@v5

Customization

Create a .headerrc.yml file in either the .github or root diretory of your project.

๐Ÿ“ฆroot
 โ”ฃ ๐Ÿ“‚.github
 โ”ƒ โ”ฃ ๐Ÿ“‚workflows
 โ”ƒ โ”ƒ โ”— ๐Ÿ“œadd-header-workflow.yml
 โ”ƒ โ”— ๐Ÿ“œ.headerrc.yml             # <---- Either here
 โ”— ๐Ÿ“œ.gitignore

๐Ÿ“ฆroot
 โ”ฃ ๐Ÿ“œ.headerrc.yml               # <---- Or here
 โ”— ๐Ÿ“œ.gitignore

This action loads default values from the headerrc-default.yml (this is built into the action), then merges them with the values from the .headerrc.yml file from your repo.

The following are a list of configurable options in the .headerrc.yml:

# Choose what to do with the header.
# remove  =  Remove an existing header from matching files.
# add     =  Add the header to any matching files.
header_action: add # Default: add

# Decide the method for choosing which files to add headers to.
# opt-out  =  All files will be selected unless the file path matches untracked_files.
# opt-in   =  No files will be selected unless the file path matches anything in tracked_files.
file_mode: opt-out # Default: opt-out

# A list of regex used to match file paths to receive the header. (opt-in mode only)
tracked_files: 
  - ^README.md$

# A list of regex used to match file paths to be skipped. (opt-out mode only)
# All file paths *not* matched will receive a header.
untracked_files:
  - app/
  - ^Dockerfile$

# Automatically add everything in the .gitignore file into the untracked_files section.
# This can save lots of time because most of these files can be ignored.  (opt-out mode only)
untrack_gitignore: true # Default: true

use_default_file_settings: true # Default: true

# The header to be added. Do not add the comment (#, //) here, see the file_associations section for that.
header: |
  SUPER SECRET CONFIDENTIAL

  [2023] - [Infinity and Beyond] ACME Inc
  All Rights Reserved.
  
  NOTICE: This is super secret info that
  must be protected at all costs.

# Customize the negation character. See below for how to use this.
# Any *default* file assocation that has this character at the beginning of the (key/value) will be removed. This only works if it is matched exactly. 
negate_characters: "!" # Default: "!"

# Group mulitple items by the comment value.
file_associations_by_comment:
  "#": 
    - "^.gitignore$"
    - "!^.gitignore$" # <-- Negate default items like this
    - ".gitignore$" # <---- You can also re-add any negated items
  "//": 
    - ".js$"
    - ".ts$"

# The item extension and the assocated comment. Overrides file_associations_by_comment if duplicates.
# Remember the escape charter for yml is "\"
# Here, you can only negate items by their key
file_associations_by_extension:
  ".*\.ya?ml$": "#"
  "!.md": ["<!--", "-->"] # <--- Negate default items like this

# For files that have 'important' first lines (like bash), use this setting to move the header below that line.
# Here, you can only negate items by their key.
skip_lines_that_have:
  ".sh$": ["#!"]

Understanding Negation

This action comes pre-loaded with many common files types in the headerrc-default.yml. However, some of these file types may be incorrect for your project. To fix this, we allow negation of default items.

To negate something, the format is <negate_characters><item headerrc-default.yml>.

For example, we filter out the .gitignore in the headerrc-default.yml

untracked_files:
  - ^\.gitignore

But if you would like to remove this item from the untracked_files. Simply add it to your .headerrc.yml with the negation_characters as the prefix. It must match EXACTLY with is in the in the headerrc-default.yml.

untracked_files:
  - !^\.gitignore  <-- Negate ^\.gitignore

You can also change the negate_characters to be anything you'd like if the default clashes with your regex.

negate_characters: "++" # Default "!"

What can be negated?

  1. tracked_files
  2. untracked_files
  3. file_associations_by_comment
  4. file_associations_by_extension
  5. skip_lines_that_have

Negation is an easy way to remove the default settings, but if we have a file association wrong, please submit an Issue or PR so we can fix it for everyone.

Default argumnet values

If your choose not to set any arguments in your GitHub workflows, they will take the following values:

dry-run: false 
verbose: false
file-name: .headerrc.yml # Located in either the `.github` or *root* diretory of your project.

Developing & Contributing

Pull Requests are welcome. See the DevContainer folder for more information