-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
149 lines (139 loc) · 5.17 KB
/
Copy pathaction.yml
File metadata and controls
149 lines (139 loc) · 5.17 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: 'Update Packmind Artifacts'
author: 'PackmindHub'
description: 'Run packmind-cli install on a working branch and open (or update) a pull request with the latest Packmind playbook artifacts.'
branding:
icon: 'refresh-cw'
color: 'blue'
inputs:
packmind-api-key:
description: 'API key for Packmind. Pass as a secret (PACKMIND_API_KEY_V3).'
required: true
github-token:
description: 'Token used to push the working branch and open the pull request. Defaults to the workflow token.'
required: false
default: ${{ github.token }}
branch-name:
description: 'Working branch for the artifact update. Created if missing, otherwise reused and merged with the base branch.'
required: false
default: 'packmind-cli-update'
base-branch:
description: 'Base branch the pull request targets and that the working branch is merged from.'
required: false
default: 'main'
node-version:
description: 'Node.js version installed before running packmind-cli.'
required: false
default: '22.17.0'
commit-message:
description: 'Commit message used when artifacts changed.'
required: false
default: 'chore(packmind): nightly artifacts update'
pr-title:
description: 'Title for the pull request when one is opened. Falls back to commit-message when empty.'
required: false
default: ''
pr-body:
description: 'Body for the pull request when one is opened.'
required: false
default: |
Automated update of Packmind artifacts via `packmind-cli install`. Review the diff under `.packmind/` and `packmind-lock.json`.
git-user-name:
description: 'Git user.name used for the commit.'
required: false
default: 'packmind-bot'
git-user-email:
description: 'Git user.email used for the commit.'
required: false
default: 'packmind-bot@users.noreply.github.com'
outputs:
changed:
description: 'Whether artifacts changed. "true" or "false".'
value: ${{ steps.diff.outputs.changed }}
pr-url:
description: 'URL of the pull request associated with the working branch (newly created or already open).'
value: ${{ steps.pr.outputs.url }}
pr-number:
description: 'Number of the pull request associated with the working branch (newly created or already open).'
value: ${{ steps.pr.outputs.number }}
runs:
using: composite
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- name: Install @packmind/cli globally
shell: bash
run: npm install -g @packmind/cli
- name: Configure git and switch to working branch
shell: bash
env:
BRANCH_NAME: ${{ inputs.branch-name }}
BASE_BRANCH: ${{ inputs.base-branch }}
GIT_USER_NAME: ${{ inputs.git-user-name }}
GIT_USER_EMAIL: ${{ inputs.git-user-email }}
run: |
git config user.name "$GIT_USER_NAME"
git config user.email "$GIT_USER_EMAIL"
if git ls-remote --exit-code --heads origin "$BRANCH_NAME"; then
git fetch origin "$BRANCH_NAME"
git checkout "$BRANCH_NAME"
git merge --no-edit "origin/$BASE_BRANCH" || true
else
git checkout -b "$BRANCH_NAME"
fi
- name: Run packmind-cli install
shell: bash
env:
PACKMIND_API_KEY_V3: ${{ inputs.packmind-api-key }}
run: packmind-cli install
- name: Detect changes
id: diff
shell: bash
run: |
if [ -z "$(git status --porcelain)" ]; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "No artifact changes — skipping commit/PR."
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Commit and push changes
if: steps.diff.outputs.changed == 'true'
shell: bash
env:
BRANCH_NAME: ${{ inputs.branch-name }}
COMMIT_MESSAGE: ${{ inputs.commit-message }}
run: |
git add -A
git commit -m "$COMMIT_MESSAGE"
git push origin "$BRANCH_NAME"
- name: Open or report pull request
id: pr
if: steps.diff.outputs.changed == 'true'
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
BRANCH_NAME: ${{ inputs.branch-name }}
BASE_BRANCH: ${{ inputs.base-branch }}
COMMIT_MESSAGE: ${{ inputs.commit-message }}
PR_TITLE: ${{ inputs.pr-title }}
PR_BODY: ${{ inputs.pr-body }}
run: |
existing=$(gh pr list --head "$BRANCH_NAME" --state open --json number,url --jq '.[0] // empty')
if [ -z "$existing" ]; then
title="$PR_TITLE"
if [ -z "$title" ]; then
title="$COMMIT_MESSAGE"
fi
url=$(gh pr create \
--base "$BASE_BRANCH" \
--head "$BRANCH_NAME" \
--title "$title" \
--body "$PR_BODY")
echo "url=$url" >> "$GITHUB_OUTPUT"
echo "number=$(gh pr view "$url" --json number --jq '.number')" >> "$GITHUB_OUTPUT"
else
echo "url=$(echo "$existing" | jq -r '.url')" >> "$GITHUB_OUTPUT"
echo "number=$(echo "$existing" | jq -r '.number')" >> "$GITHUB_OUTPUT"
echo "An open PR already exists for $BRANCH_NAME; new commits were appended to it."
fi