From 8d48c843412c2688d5b79e21b10bc9eb728c1bba Mon Sep 17 00:00:00 2001
From: Matthew Baggett <matthew@baggett.me>
Date: Sat, 18 May 2024 18:15:29 +0200
Subject: [PATCH] Add qualitycontrol.

---
 .actrc                             |  6 ++++
 .github/workflows/test.yml         | 57 ++++++++++++++++++++++++++++++
 .github/workflows/trunk.cache.yml  | 31 ++++++++++++++++
 .github/workflows/trunk.check.yml  | 28 +++++++++++++++
 .trunk/.gitignore                  |  9 +++++
 .trunk/configs/.checkov.yaml       |  3 ++
 .trunk/configs/.hadolint.yaml      |  3 ++
 .trunk/configs/.markdownlint.yaml  | 10 ++++++
 .trunk/configs/.markdownlintignore |  1 +
 .trunk/configs/.shellcheck         |  0
 .trunk/configs/.shellcheckrc       |  6 ++++
 .trunk/configs/.yamllint.yaml      | 15 ++++++++
 .trunk/trunk.yaml                  | 37 +++++++++++++++++++
 README.md                          |  7 ++++
 action.yml                         |  3 +-
 15 files changed, 215 insertions(+), 1 deletion(-)
 create mode 100644 .actrc
 create mode 100644 .github/workflows/test.yml
 create mode 100644 .github/workflows/trunk.cache.yml
 create mode 100644 .github/workflows/trunk.check.yml
 create mode 100644 .trunk/.gitignore
 create mode 100644 .trunk/configs/.checkov.yaml
 create mode 100644 .trunk/configs/.hadolint.yaml
 create mode 100644 .trunk/configs/.markdownlint.yaml
 create mode 100644 .trunk/configs/.markdownlintignore
 create mode 100644 .trunk/configs/.shellcheck
 create mode 100644 .trunk/configs/.shellcheckrc
 create mode 100644 .trunk/configs/.yamllint.yaml
 create mode 100644 .trunk/trunk.yaml

diff --git a/.actrc b/.actrc
new file mode 100644
index 0000000..f81e275
--- /dev/null
+++ b/.actrc
@@ -0,0 +1,6 @@
+--use-new-action-cache
+--platform self-hosted=ghcr.io/catthehacker/ubuntu:act-latest
+--platform ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest
+--platform ubuntu-22.04=ghcr.io/catthehacker/ubuntu:act-22.04
+--platform ubuntu-20.04=ghcr.io/catthehacker/ubuntu:act-20.04
+--platform ubuntu-18.04=ghcr.io/catthehacker/ubuntu:act-18.04
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..55c2a87
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,57 @@
+name: Test
+
+permissions: read-all
+
+on:
+  push:
+
+concurrency:
+  group: ${{ github.head_ref || github.run_id }}
+  cancel-in-progress: true
+
+jobs:
+  test-from-env:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+      - uses: ./.
+      - name: Verify Date
+        run: |
+          echo "DATE: $DATE"
+          echo "TODAY: $(date +'%Y-%m-%d')"
+          if [ "$DATE" != "$(date +'%Y-%m-%d')" ]; then
+              echo "DATE is not today's date"
+              exit 1
+          fi
+      - name: Verify TIME within 10 seconds of now
+        run: |
+          echo "TIME: $TIME"
+          echo "NOW: $(date +'%H:%M:%S')"
+          if [ $(date -d "$TIME" +%s) -lt $(date -d "now - 10 seconds" +%s) ] || [ $(date -d "$TIME" +%s) -gt $(date -d "now + 10 seconds" +%s) ]; then
+              echo "TIME is not within 10 seconds of now"
+              exit 1
+          fi
+
+  test-from-output:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+      - id: date
+        uses: ./.
+      - name: Verify Date
+        run: |
+          echo "DATE: ${{ steps.date.outputs.date }}"
+          echo "TODAY: $(date +'%Y-%m-%d')"
+          if [ "${{ steps.date.outputs.date }}" != "$(date +'%Y-%m-%d')" ]; then
+              echo "DATE is not today's date"
+              exit 1
+          fi
+      # Verify that date.time is within 10 seconds of now.
+      - name: Verify TIME within 10 seconds of now
+        run: |
+          echo "TIME: ${{ steps.date.outputs.time }}"
+          echo "NOW: $(date +'%H:%M:%S')"
+          if [ $(date -d "${{ steps.date.outputs.time }}" +%s) -lt $(date -d "now - 10 seconds" +%s) ] || [ $(date -d "${{ steps.date.outputs.time }}" +%s) -gt $(date -d "now + 10 seconds" +%s) ]; then
+              echo "TIME is not within 10 seconds of now"
+              exit 1
+          fi
diff --git a/.github/workflows/trunk.cache.yml b/.github/workflows/trunk.cache.yml
new file mode 100644
index 0000000..97daa79
--- /dev/null
+++ b/.github/workflows/trunk.cache.yml
@@ -0,0 +1,31 @@
+name: "Quality Control: Trunk Cache"
+
+permissions: read-all
+
+on:
+  workflow_call:
+  workflow_dispatch:
+  push:
+    branches:
+      - main
+    paths:
+      - .trunk/trunk.yaml
+  schedule:
+    - cron: "0 9 * * 1" # 9am Tooling Monday
+
+concurrency:
+  group: ${{ github.head_ref || github.run_id }}
+  cancel-in-progress: true
+
+jobs:
+  trunk-cache:
+    name: Trunk Cache
+    runs-on: ubuntu-latest
+    permissions:
+      actions: write
+    steps:
+      - uses: actions/checkout@v4
+      - name: "Trunk Cache"
+        uses: trunk-io/trunk-action@v1
+        with:
+          check-mode: populate_cache_only
diff --git a/.github/workflows/trunk.check.yml b/.github/workflows/trunk.check.yml
new file mode 100644
index 0000000..0d9c7e8
--- /dev/null
+++ b/.github/workflows/trunk.check.yml
@@ -0,0 +1,28 @@
+name: "Quality Control: Trunk Check"
+
+permissions: read-all
+
+on:
+  workflow_call:
+  workflow_dispatch:
+  push:
+    branches:
+      - main
+  schedule:
+    - cron: "0 11 * * 2" # 11am Patch Tuesday
+
+concurrency:
+  group: ${{ github.head_ref || github.run_id }}
+  cancel-in-progress: true
+
+jobs:
+  trunk-check:
+    name: Trunk Check Runner
+    runs-on: ubuntu-latest
+    permissions:
+      checks: write # For trunk to post annotations
+      contents: read # For repo checkout
+    steps:
+      - uses: actions/checkout@v4
+      - name: "Trunk Check"
+        uses: trunk-io/trunk-action@v1
diff --git a/.trunk/.gitignore b/.trunk/.gitignore
new file mode 100644
index 0000000..15966d0
--- /dev/null
+++ b/.trunk/.gitignore
@@ -0,0 +1,9 @@
+*out
+*logs
+*actions
+*notifications
+*tools
+plugins
+user_trunk.yaml
+user.yaml
+tmp
diff --git a/.trunk/configs/.checkov.yaml b/.trunk/configs/.checkov.yaml
new file mode 100644
index 0000000..8331ca9
--- /dev/null
+++ b/.trunk/configs/.checkov.yaml
@@ -0,0 +1,3 @@
+---
+skip-check:
+  - CKV_SECRET_* # Skip all checks that start with CKV_SECRET, we already have gitleaks doing this.
diff --git a/.trunk/configs/.hadolint.yaml b/.trunk/configs/.hadolint.yaml
new file mode 100644
index 0000000..d700141
--- /dev/null
+++ b/.trunk/configs/.hadolint.yaml
@@ -0,0 +1,3 @@
+ignored:
+  - DL3006
+  - DL3008
diff --git a/.trunk/configs/.markdownlint.yaml b/.trunk/configs/.markdownlint.yaml
new file mode 100644
index 0000000..fb94039
--- /dev/null
+++ b/.trunk/configs/.markdownlint.yaml
@@ -0,0 +1,10 @@
+# Autoformatter friendly markdownlint config (all formatting rules disabled)
+default: true
+blank_lines: false
+bullet: false
+html: false
+indentation: false
+line_length: false
+spaces: false
+url: false
+whitespace: false
diff --git a/.trunk/configs/.markdownlintignore b/.trunk/configs/.markdownlintignore
new file mode 100644
index 0000000..bf789ea
--- /dev/null
+++ b/.trunk/configs/.markdownlintignore
@@ -0,0 +1 @@
+LICENCE.md
diff --git a/.trunk/configs/.shellcheck b/.trunk/configs/.shellcheck
new file mode 100644
index 0000000..e69de29
diff --git a/.trunk/configs/.shellcheckrc b/.trunk/configs/.shellcheckrc
new file mode 100644
index 0000000..8cc03cd
--- /dev/null
+++ b/.trunk/configs/.shellcheckrc
@@ -0,0 +1,6 @@
+enable=all
+source-path=SCRIPTDIR
+
+# If you're having issues with shellcheck following source, disable the errors via:
+# disable=SC1090
+# disable=SC1091
diff --git a/.trunk/configs/.yamllint.yaml b/.trunk/configs/.yamllint.yaml
new file mode 100644
index 0000000..984573e
--- /dev/null
+++ b/.trunk/configs/.yamllint.yaml
@@ -0,0 +1,15 @@
+extends: relaxed
+rules:
+  quoted-strings:
+    required: only-when-needed
+    extra-allowed: ["{|*}"]
+  empty-values:
+    forbid-in-block-mappings: false
+    forbid-in-flow-mappings: false
+    ignore:
+      - .github/workflows/*.yml
+  key-duplicates: {}
+  octal-values:
+    forbid-implicit-octal: true
+  document-start: disable
+  line-length: disable
diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml
new file mode 100644
index 0000000..f88fc1f
--- /dev/null
+++ b/.trunk/trunk.yaml
@@ -0,0 +1,37 @@
+# This file controls the behavior of Trunk: https://docs.trunk.io/cli
+# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
+version: 0.1
+cli:
+  version: 1.22.1
+# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
+plugins:
+  sources:
+    - id: trunk
+      ref: v1.5.0
+      uri: https://github.com/trunk-io/plugins
+# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
+runtimes:
+  enabled:
+    - node@18.12.1
+    - python@3.10.8
+# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
+lint:
+  disabled:
+    - git-diff-check
+  enabled:
+    - actionlint@1.7.0
+    - checkov@3.2.95
+    - markdownlint@0.40.0
+    - prettier@3.2.5
+    - trivy@0.51.1
+    - trufflehog@3.76.3
+    - yamllint@1.35.1
+actions:
+  enabled:
+    - trunk-announce
+    - trunk-check-pre-push
+    - trunk-fmt-pre-commit
+    - trunk-upgrade-available
+tools:
+  enabled:
+    - act@0.2.62
diff --git a/README.md b/README.md
index b654f34..f89fdda 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,9 @@
 # action-get-datetime
+
 Simple action that names datetimes more useful in github actions.
+
+Use it like so:
+
+```yaml
+
+```
diff --git a/action.yml b/action.yml
index 3e6ce81..8310acd 100644
--- a/action.yml
+++ b/action.yml
@@ -22,6 +22,7 @@ runs:
           echo "$var=$value" | tee -a "$GITHUB_OUTPUT"
           echo "${var^^}=$value" >> "$GITHUB_ENV"
         done
+
 outputs:
   datetime:
     description: "Current date and time in 'YYYY-MM-DD HH:MM:SS' format"
@@ -37,4 +38,4 @@ outputs:
     value: ${{ steps.date.outputs.atom }}
   atom_with_millis:
     description: "Current date and time in 'YYYY-MM-DDTHH:MM:SS.SSSZ' format"
-    value: ${{ steps.date.outputs.atom_with_millis }}
\ No newline at end of file
+    value: ${{ steps.date.outputs.atom_with_millis }}