-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (91 loc) · 3.99 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: dotCMS sync
on: [push]
jobs:
sync-with-dotcms:
runs-on: ubuntu-latest
env:
# Global environment expected by dotCMS CLI
# This is how we instruct the cli the target server
DOT_API_URL: ${{ vars.DOT_API_URL }}
# This is how we instruct the cli the target folder in the repo
# By default it must be the root of the repo this allows setting up a different folder on top of the root
DOT_REPO_BASE_PATH: ${{ vars.DOT_REPO_BASE_PATH }}
# This is how we instruct the cli to create the workspace if it does not exist
DOT_CREATE_WORKSPACE: ${{ vars.DOT_CREATE_WORKSPACE || 'true' }}
# This is the CLI version to use, but we can always override this value
DOT_CLI_JAR_DOWNLOAD_URL: ${{ vars.DOT_CLI_JAR_DOWNLOAD_URL || 'https://repo.dotcms.com/artifactory/libs-snapshot-local/com/dotcms/dotcms-cli/1.0.0-SNAPSHOT/dotcms-cli-1.0.0-20231002.205953-1.jar' }}
# In case we want to force the download of the CLI jar
DOT_FORCE_DOWNLOAD: ${{ vars.DOT_FORCE_DOWNLOAD || 'false' }}
steps:
- name: Checkout
uses: actions/checkout@v4
id: checkout
with:
fetch-depth: 0
- name: Load .env file
uses: aarcangeli/[email protected]
with:
if-file-not-found: 'warn'
- name: Print env vars
run: |
echo "$GITHUB_ENV"
- name: Get changes
run: |
git diff --name-only ${{ github.event.before }} ${{ github.event.after }} > changed_files.txt
- name: List changed files
run: |
while IFS= read -r line
do
echo "\"$line\" was changed"
done < changed_files.txt
- name: Github Event Context properties
run: |
echo "Event: ${{ github.event }}"
echo "Event Name: ${{ github.event_name }}"
echo "Repository: ${{ github.repository }}"
echo "Commit SHA: ${{ github.sha }}"
echo "Commit Ref: ${{ github.ref }}"
echo "Head Ref: ${{ github.head_ref }}"
echo "Base Ref: ${{ github.base_ref }}"
echo "Triggered by: ${{ github.actor }}"
echo "Workflow: ${{ github.workflow }}"
echo "PR: ${{ github.pull_request }}"
echo "Workspace: ${{ github.workspace }}"
- name: Create workspace if not exists
id: dot-workspace
run: |
if [ ${{ env.DOT_CREATE_WORKSPACE }} = true ]; then
echo "Creating workspace ::: "
chmod +x ./.github/workflows/scripts/workspace.sh
source ./.github/workflows/scripts/workspace.sh
workspace_updated=$(create_workspace "${{github.workspace}}${{env.DOT_REPO_BASE_PATH}}" )
echo "workspace-updated=$workspace_updated" >> "$GITHUB_OUTPUT"
fi
shell: bash
# This step requires permission to push to the repo
# you need to grant read/write permission for workflows in the repo settings
- name: Persist updated workspace
run: |
saveChanges="${{ steps.dot-workspace.outputs.workspace-updated }}"
if [ -n "${saveChanges}" ]; then
git config user.name "${{ secrets.CI_MACHINE_USER }}"
git config user.email "[email protected]"
git add .
git commit -m "pushing workspace changes"
git push
echo "Workspace has been updated."
fi
- name: Run dotCMS CLI
id: dot-push
run: |
chmod +x ./.github/workflows/scripts/run-push.sh
source ./.github/workflows/scripts/run-push.sh
install_cli "${{env.DOT_CLI_JAR_DOWNLOAD_URL}}" "${{env.DOT_FORCE_DOWNLOAD}}"
run_cli_push "${{github.workspace}}${{env.DOT_REPO_BASE_PATH}}" "${{ secrets.DOT_TOKEN }}" "${{ env.DOT_CLI_OPTS }}"
echo "exit-code=$exit_code" >> "$GITHUB_OUTPUT"
print_log
if [ $exit_code -ne 0 ]; then
echo "Error running dotCMS CLI"
exit 1
fi
shell: bash