Skip to content

Commit f1ce10e

Browse files
authored
Initial commit
0 parents  commit f1ce10e

File tree

10 files changed

+391
-0
lines changed

10 files changed

+391
-0
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# CHANGE_ME - set correct code owner
2+
* @linz/step-enablement

.github/dependabot.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
8+
updates:
9+
- package-ecosystem: "github-actions"
10+
directory: "/"
11+
schedule:
12+
interval: weekly
13+
commit-message:
14+
prefix: "fix(deps)"
15+
cooldown:
16+
default-days: 15

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
branches: [master]
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
steps:
12+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
13+
14+
# CHANGE_ME - implement automation test for the actual action
15+
- name: invoke action
16+
uses: ./
17+
with:
18+
input1: foo
19+
input2: bar
20+
21+
- name: Verify the result
22+
run: |
23+
source assert.sh
24+
assert_eq "foo" "$DUMMY_INPUT1"
25+
assert_eq "bar" "$DUMMY_INPUT2"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Dependabot automation
2+
3+
on: pull_request
4+
5+
permissions:
6+
contents: write
7+
pull-requests: write
8+
9+
jobs:
10+
dependabot:
11+
runs-on: ubuntu-latest
12+
if: github.actor == 'dependabot[bot]'
13+
steps:
14+
- name: Dependabot metadata
15+
id: metadata
16+
uses: dependabot/fetch-metadata@08eff52bf64351f401fb50d4972fa95b9f2c2d1b # v2.4.0
17+
with:
18+
github-token: "${{ secrets.GITHUB_TOKEN }}"
19+
- name: Approve PR
20+
run: gh pr review --approve "$PR_URL"
21+
env:
22+
PR_URL: ${{ github.event.pull_request.html_url }}
23+
GITHUB_TOKEN: ${{ secrets.STEP_GITHUB_ACTION_TOKEN }}
24+
- name: Enable auto-merge for Dependabot PRs that doesn't include major version update
25+
if: steps.metadata.outputs.update-type != 'version-update:semver-major'
26+
run: gh pr merge --auto --squash "$PR_URL"
27+
env:
28+
PR_URL: ${{ github.event.pull_request.html_url }}
29+
GITHUB_TOKEN: ${{ secrets.STEP_GITHUB_ACTION_TOKEN }}
30+

.github/workflows/lint-pr.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: "Lint PR"
2+
3+
on:
4+
pull_request:
5+
types: ["opened", "edited", "reopened", "synchronize"]
6+
7+
jobs:
8+
pr-lint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: linz/action-pull-request-lint@7adb4bc59b59dc6e097de831c29a17c2c1338826 # v1.2.0

.github/workflows/release.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: release-please
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
release-please:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: googleapis/release-please-action@16a9c90856f42705d54a6fda1823352bdc62cf38 # v4.4.0
17+
with:
18+
release-type: simple
19+
token: ${{ secrets.STEP_GITHUB_ACTION_TOKEN }}

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# template-github-action
2+
3+
Template repo to kick start a composite Github action, providing the following features and configurations
4+
5+
1. [Sample composite action](action.yaml)
6+
2. [Sample CI workflow](.github/workflows/ci.yml) to test the sample action
7+
- provided [assert.sh](assert.sh) to perform simple assertions in shell
8+
3. [Repo setup script](setup_repo.sh) to configure the new repo
9+
4. PR title linting to enforce that the PR titles follows [conventional commit standard](https://www.conventionalcommits.org/)
10+
5. Configures dependabot to update any Github action dependencies
11+
6. Dependabot automation workflow to automatically approve and squash merge dependabot PRs
12+
7. Automated release with [release-please](https://github.com/googleapis/release-please-action)
13+
8. Sample [CODEOWNERS](.github/CODEOWNERS) file
14+
15+
## Template usage
16+
17+
1. When creating a new repo
18+
1. Recommend to prefix the repo name with `action-`, e.g. `action-setup-playwright`
19+
2. Use the `Start with a template` option and select this repo as the template.
20+
3. Clone the new repo
21+
4. Make sure you have [Github CLI](https://github.com/cli/cli#installation) installed
22+
5. Open a bash terminal to the repo folder
23+
6. Run `./setup_repo.sh` to configure the repo settings. Note - this script self-deletes after successful run, commit
24+
the deletion as the script would be no longer required.
25+
2. Search for word `CHANGE_ME` and modify the code as needed.
26+
3. Replace this README file with documentation for the new action.
27+
4. Implement the new action and release it with release-please
28+
5. Ask in Slack channel `#team-step-enablement` or `#help-github` to grant dependabot access to this new repo
29+
1. so that consumers of your new action can receive automated upgrades when new version is released
30+
2. this setting is at the bottom of this page https://github.com/organizations/linz/settings/security_analysis

action.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# CHANGE_ME - implement the actual action
2+
name: dummy composite action
3+
4+
inputs:
5+
input1:
6+
description: value to set to DUMMY_INPUT1 environment variable
7+
input2:
8+
description: value to set to DUMMY_INPUT2 environment variable
9+
10+
runs:
11+
using: composite
12+
steps:
13+
- name: Dummy step 1
14+
shell: bash
15+
env:
16+
INPUT1: ${{ inputs.input1 }}
17+
INPUT2: ${{ inputs.input2 }}
18+
run: |
19+
echo "DUMMY_INPUT1=$INPUT1" >> $GITHUB_ENV
20+
echo "DUMMY_INPUT2=$INPUT2" >> $GITHUB_ENV

assert.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env bash
2+
# copied from https://github.com/torokmark/assert.sh/blob/main/assert.sh
3+
4+
#####################################################################
5+
##
6+
## title: Assert Extension
7+
##
8+
## description:
9+
## Assert extension of shell (bash, ...)
10+
## with the common assert functions
11+
## Function list based on:
12+
## http://junit.sourceforge.net/javadoc/org/junit/Assert.html
13+
## Log methods : inspired by
14+
## - https://natelandau.com/bash-scripting-utilities/
15+
## author: Mark Torok
16+
##
17+
## date: 07. Dec. 2016
18+
##
19+
## license: MIT
20+
##
21+
#####################################################################
22+
23+
if command -v tput &>/dev/null && tty -s; then
24+
RED=$(tput setaf 1)
25+
GREEN=$(tput setaf 2)
26+
MAGENTA=$(tput setaf 5)
27+
NORMAL=$(tput sgr0)
28+
BOLD=$(tput bold)
29+
else
30+
RED=$(echo -en "\e[31m")
31+
GREEN=$(echo -en "\e[32m")
32+
MAGENTA=$(echo -en "\e[35m")
33+
NORMAL=$(echo -en "\e[00m")
34+
BOLD=$(echo -en "\e[01m")
35+
fi
36+
37+
log_header() {
38+
printf "\n${BOLD}${MAGENTA}========== %s ==========${NORMAL}\n" "$@" >&2
39+
}
40+
41+
log_success() {
42+
printf "${GREEN}✔ %s${NORMAL}\n" "$@" >&2
43+
}
44+
45+
log_failure() {
46+
printf "${RED}✖ %s${NORMAL}\n" "$@" >&2
47+
}
48+
49+
assert_eq() {
50+
local expected="$1"
51+
local actual="$2"
52+
local msg="${3-}"
53+
54+
if [ "$expected" == "$actual" ]; then
55+
return 0
56+
else
57+
[ "${#msg}" -gt 0 ] && log_failure "$expected == $actual :: $msg" || true
58+
return 1
59+
fi
60+
}
61+
62+
assert_not_eq() {
63+
local expected="$1"
64+
local actual="$2"
65+
local msg="${3-}"
66+
67+
if [ ! "$expected" == "$actual" ]; then
68+
return 0
69+
else
70+
[ "${#msg}" -gt 0 ] && log_failure "$expected != $actual :: $msg" || true
71+
return 1
72+
fi
73+
}
74+
75+
assert_true() {
76+
local actual="$1"
77+
local msg="${2-}"
78+
79+
assert_eq true "$actual" "$msg"
80+
return "$?"
81+
}
82+
83+
assert_false() {
84+
local actual="$1"
85+
local msg="${2-}"
86+
87+
assert_eq false "$actual" "$msg"
88+
return "$?"
89+
}
90+
91+
assert_empty() {
92+
local actual=$1
93+
local msg="${2-}"
94+
95+
assert_eq "" "$actual" "$msg"
96+
return "$?"
97+
}
98+
99+
assert_contain() {
100+
local haystack="$1"
101+
local needle="${2-}"
102+
local msg="${3-}"
103+
104+
if [ -z "${needle:+x}" ]; then
105+
return 0
106+
fi
107+
108+
if [ -z "$haystack" ]; then
109+
return 1
110+
fi
111+
112+
if [ -z "${haystack##*$needle*}" ]; then
113+
return 0
114+
else
115+
[ "${#msg}" -gt 0 ] && log_failure "$haystack doesn't contain $needle :: $msg" || true
116+
return 1
117+
fi
118+
}
119+

0 commit comments

Comments
 (0)