Skip to content

Commit 4b74a88

Browse files
Merge pull request #339 from wttech/hardened-wrapper-scripts
Hardened wrapper scripts
2 parents 6d5256f + 09a9e52 commit 4b74a88

13 files changed

Lines changed: 1128 additions & 132 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ jobs:
3838
uses: actions/checkout@v4
3939

4040
- name: Run build
41-
run: make
41+
run: sh taskw cli:all

.gitignore

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
*.so
2929
*.dylib
3030

31+
# Package Files #
32+
*.jar
33+
*.war
34+
*.ear
35+
3136
# Test binary, built with `go test -c`
3237
*.test
3338

@@ -235,4 +240,10 @@ dist/
235240
!*.code-workspace
236241

237242
# Built Visual Studio Code Extensions
238-
*.vsix
243+
*.vsix
244+
245+
# AEM Compose
246+
aem/home/
247+
.task/
248+
.env
249+
.env.*
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
18+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar

Makefile

Lines changed: 0 additions & 41 deletions
This file was deleted.

Taskfile.aem.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
version: '3'
2+
3+
tasks:
4+
init:
5+
desc: initialize project
6+
cmds:
7+
- sh aemw project init -V ALL
8+
9+
setup:
10+
desc: start and provision AEM instances
11+
cmds:
12+
- task: start
13+
- task: provision
14+
- task: check
15+
16+
resetup:
17+
desc: destroy then setup again AEM instances
18+
cmds:
19+
- task: destroy
20+
- task: setup
21+
22+
start:
23+
desc: start AEM instances
24+
aliases: [ up ]
25+
cmd: sh aemw instance launch
26+
27+
stop:
28+
desc: stop AEM instances
29+
aliases: [ down ]
30+
cmd: sh aemw instance stop
31+
32+
restart:
33+
desc: restart AEM instances
34+
cmds:
35+
- task: stop
36+
- task: start
37+
38+
destroy:
39+
desc: destroy AEM instances
40+
prompt: This will permanently delete all configured AEM instances and their data. Continue?
41+
deps: [ stop ]
42+
cmd: sh aemw instance destroy
43+
44+
status:
45+
desc: check status of AEM instances
46+
env:
47+
AEM_OUTPUT_VALUE: ALL
48+
cmd: sh aemw instance status
49+
50+
tail:
51+
desc: tail logs of AEM instances
52+
cmd: tail -f aem/home/var/instance/*/crx-quickstart/logs/{stdout,error}.log
53+
54+
tail:author:
55+
desc: tail logs of AEM author instance
56+
cmd: tail -f aem/home/var/instance/author/crx-quickstart/logs/{stdout,error}.log
57+
58+
tail:publish:
59+
desc: tail logs of AEM publish instance
60+
cmd: tail -f aem/home/var/instance/publish/crx-quickstart/logs/{stdout,error}.log
61+
62+
provision:
63+
desc: provision AEM instances by installing packages and applying configurations
64+
aliases: [ configure ]
65+
cmds:
66+
- task: provision:repl-agent-publish
67+
- task: provision:crx
68+
69+
provision:repl-agent-publish:
70+
desc: configure replication agent on AEM author instance
71+
internal: true
72+
cmd: |
73+
PROPS="
74+
enabled: true
75+
transportUri: {{.AEM_PUBLISH_HTTP_URL}}/bin/receive?sling:authRequestLogin=1
76+
transportUser: {{.AEM_PUBLISH_USER}}
77+
transportPassword: {{.AEM_PUBLISH_PASSWORD}}
78+
userId: admin
79+
"
80+
echo "$PROPS" | sh aemw repl agent setup -A --location "author" --name "publish"
81+
82+
provision:crx:
83+
desc: enable CRX/DE on AEM instances
84+
internal: true
85+
cmd: 'sh aemw osgi config save --pid "org.apache.sling.jcr.davex.impl.servlets.SlingDavExServlet" --input-string "alias: /crx/server"'
86+
87+
check:
88+
deps: [ author:check, publish:check ]
89+
90+
author:check:
91+
desc: check health of AEM author instance
92+
cmds:
93+
- curl -s -u "{{.AEM_AUTHOR_USER}}:{{.AEM_AUTHOR_PASSWORD}}" "{{.AEM_AUTHOR_HTTP_URL}}/libs/granite/core/content/login.html" | grep -q "QUICKSTART_HOMEPAGE"
94+
- curl -s -u "{{.AEM_AUTHOR_USER}}:{{.AEM_AUTHOR_PASSWORD}}" "{{.AEM_AUTHOR_HTTP_URL}}/etc/replication/agents.author/publish.test.html" | grep -q "Replication (TEST) of /content successful"
95+
96+
publish:check:
97+
desc: check health of AEM publish instance
98+
cmd: curl -s -u "{{.AEM_PUBLISH_USER}}:{{.AEM_PUBLISH_PASSWORD}}" "{{.AEM_PUBLISH_HTTP_URL}}/libs/granite/core/content/login.html" | grep -q "QUICKSTART_HOMEPAGE"
99+

Taskfile.cli.yml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
version: '3'
2+
3+
tasks:
4+
all:
5+
desc: Run deps, test, vet, fmt, lint, install
6+
cmds:
7+
- task: deps
8+
- task: test
9+
- task: vet
10+
- task: fmt
11+
- task: lint
12+
- task: install
13+
14+
deps:
15+
desc: Install dependencies
16+
cmds:
17+
- go install github.com/mgechev/revive@v1.3.3
18+
- go mod tidy
19+
20+
test:
21+
desc: Run tests
22+
cmds:
23+
- go test ./...
24+
25+
test:int:
26+
desc: Run integration tests
27+
cmds:
28+
- go test -tags=int_test ./...
29+
30+
vet:
31+
desc: Run go vet
32+
cmds:
33+
- go vet ./...
34+
35+
fmt:
36+
desc: Format code
37+
cmds:
38+
- gofmt -l -w .
39+
40+
lint:
41+
desc: Run linter
42+
cmds:
43+
- revive -config revive.toml -formatter friendly ./...
44+
45+
build:
46+
desc: Build the binary
47+
vars:
48+
GIT_COMMIT:
49+
sh: git rev-parse HEAD
50+
GIT_COMMIT_DATE:
51+
sh: git log -1 --date=format:'%Y-%m-%dT%H:%M:%S' --format=%cd
52+
GIT_VERSION:
53+
sh: git describe --tags 2>/dev/null || echo "{{.GIT_COMMIT}}"
54+
LD_FLAGS: "-s -w -X main.appVersion={{.GIT_VERSION}} -X main.appCommit={{.GIT_COMMIT}} -X main.appCommitDate={{.GIT_COMMIT_DATE}}"
55+
TAGS: timetzdata
56+
cmds:
57+
- go build -tags "{{.TAGS}}" --ldflags "{{.LD_FLAGS}}" -o bin/aem ./cmd/aem
58+
59+
build:other:
60+
desc: Build binaries for other platforms
61+
vars:
62+
GIT_COMMIT:
63+
sh: git rev-parse HEAD
64+
GIT_COMMIT_DATE:
65+
sh: git log -1 --date=format:'%Y-%m-%dT%H:%M:%S' --format=%cd
66+
GIT_VERSION:
67+
sh: git describe --tags 2>/dev/null || echo "{{.GIT_COMMIT}}"
68+
LD_FLAGS: "-s -w -X main.appVersion={{.GIT_VERSION}} -X main.appCommit={{.GIT_COMMIT}} -X main.appCommitDate={{.GIT_COMMIT_DATE}}"
69+
TAGS: timetzdata
70+
cmds:
71+
- GOARCH=amd64 GOOS=darwin go build -tags "{{.TAGS}}" --ldflags "{{.LD_FLAGS}}" -o bin/aem.darwin ./cmd/aem
72+
- GOARCH=amd64 GOOS=linux go build -tags "{{.TAGS}}" --ldflags "{{.LD_FLAGS}}" -o bin/aem.linux ./cmd/aem
73+
- GOARCH=amd64 GOOS=windows go build -tags "{{.TAGS}}" --ldflags "{{.LD_FLAGS}}" -o bin/aem.exe ./cmd/aem
74+
75+
install:
76+
desc: Install the binary
77+
vars:
78+
GIT_COMMIT:
79+
sh: git rev-parse HEAD
80+
GIT_COMMIT_DATE:
81+
sh: git log -1 --date=format:'%Y-%m-%dT%H:%M:%S' --format=%cd
82+
GIT_VERSION:
83+
sh: git describe --tags 2>/dev/null || echo "{{.GIT_COMMIT}}"
84+
LD_FLAGS: "-s -w -X main.appVersion={{.GIT_VERSION}} -X main.appCommit={{.GIT_COMMIT}} -X main.appCommitDate={{.GIT_COMMIT_DATE}}"
85+
TAGS: timetzdata
86+
cmds:
87+
- go install -tags "{{.TAGS}}" --ldflags "{{.LD_FLAGS}}" ./cmd/aem
88+
89+
clean:
90+
desc: Clean build artifacts
91+
cmds:
92+
- go clean
93+
- rm -fr bin
94+
95+
release:
96+
desc: Release a new version
97+
vars:
98+
VERSION: ""
99+
cmds:
100+
- |
101+
set -e
102+
103+
VERSION="{{.CLI_ARGS | default ""}}"
104+
VERSION_TAG="v$VERSION"
105+
106+
VERSION_CURRENT_TAG=$(git describe --tags --abbrev=0 || echo "v0.0.0")
107+
VERSION_CURRENT_TAG="${VERSION_CURRENT_TAG#v}" # remove leading 'v', preserve leading zeros
108+
109+
if [ -z "$VERSION" ]; then
110+
echo "Release version is not specified!"
111+
echo "Last released: ${VERSION_CURRENT_TAG}"
112+
exit 1
113+
fi
114+
115+
GIT_STAT=$(git diff --stat || true)
116+
117+
if [ "$GIT_STAT" != '' ]; then
118+
echo "Unable to release. Uncommitted changes detected!"
119+
exit 1
120+
fi
121+
122+
echo ""
123+
echo "Releasing $VERSION_TAG"
124+
echo ""
125+
126+
echo "Bumping version in files"
127+
bump_version() {
128+
local file="$1"
129+
if [ "$(uname)" = "Darwin" ]; then
130+
sed -i '' 's/AEM_CLI_VERSION:-"[^\"]*"/AEM_CLI_VERSION:-"'"$VERSION"'"/g' "$file"
131+
# shellcheck disable=SC2016
132+
sed -i '' 's/aem\@v[^\`]*\`/aem@v'"$VERSION"\`'/g' "$file"
133+
else
134+
sed -i 's/AEM_CLI_VERSION:-"[^\"]*"/AEM_CLI_VERSION:-"'"$VERSION"'"/g' "$file"
135+
# shellcheck disable=SC2016
136+
sed -i 's/aem\@v[^\`]*\`/aem@v'"$VERSION"\`'/g' "$file"
137+
fi
138+
}
139+
bump_version "README.MD"
140+
bump_version "pkg/project/common/aemw"
141+
142+
echo "Pushing version bump"
143+
git commit -a -m "Release $VERSION_TAG" || echo "No changes to commit"
144+
git push || echo "Nothing to push"
145+
146+
echo "Pushing release tag '$VERSION_TAG'"
147+
git tag "$VERSION_TAG"
148+
git push origin "$VERSION_TAG" || echo "Tag already exists or cannot push"

0 commit comments

Comments
 (0)