-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (129 loc) · 6.08 KB
/
publish-abcclassification.yml
File metadata and controls
151 lines (129 loc) · 6.08 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
150
151
# GitHub Actions workflow to publish DaxLib packages
#
# Version: 1.0.0
#
# HOW TO USE:
# 1. Go to "Actions" in your GitHub repository
# 2. Click on "publish-package" in the workflow list
# 3. Click the "Run workflow" button and confirm
# 4. Wait for the workflow to complete
# 5. Create a Pull Request to the official DaxLib repository (link provided in the summary after completion)
#
# WHAT IT DOES:
# - Reads your package from the current repository
# - Copies it to your daxlib fork
# - Creates (or updates) a branch with your changes
# - Provides you with a link to open a Pull Request to the official DaxLib repository
#
# REQUIREMENTS:
# - A fork of the daxlib repository under your account
# - A Personal Access Token (PAT) saved as DAXLIBFORK_PAT in repository secrets
name: publish-abcclassification
on:
workflow_dispatch:
permissions:
contents: read
env:
# Name of the forked daxlib repository (change if your fork has a different name)
DAXLIBFORK_NAME: ${{ github.repository_owner }}/fork-daxlib
DAXPATTERN_NAME: AbcClassification
jobs:
publish:
runs-on: ubuntu-latest
steps:
# Checkout the current repository
- name: Checkout source
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
path: source-repo
# Checkout the daxlib fork repository
- name: Checkout upstream
uses: actions/checkout@v4
with:
repository: ${{ env.DAXLIBFORK_NAME }}
path: fork-repo
token: ${{ secrets.DAXLIBFORK_PAT }}
# Configure Git
- name: Git config
working-directory: fork-repo
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
# Read the package version from the manifest
- name: Read package manifest
id: package
working-directory: source-repo
run: |
PACKAGE_NAME=$(jq -r '.id' src/${{ env.DAXPATTERN_NAME }}/manifest.daxlib)
echo "name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT
echo "Package name: ${PACKAGE_NAME}"
PACKAGE_VERSION=$(jq -r '.version' src/${{ env.DAXPATTERN_NAME }}/manifest.daxlib)
echo "version=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT
echo "Package version: ${PACKAGE_VERSION}"
PACKAGE_FOLDER="packages/$(echo "${PACKAGE_NAME}" | cut -c1 | tr '[:upper:]' '[:lower:]')/$(echo "${PACKAGE_NAME}" | tr '[:upper:]' '[:lower:]')/${PACKAGE_VERSION}"
echo "folder=${PACKAGE_FOLDER}" >> $GITHUB_OUTPUT
echo "Package folder: ${PACKAGE_FOLDER}"
# Checkout the branch (or create it if it doesn't exist)
- name: Checkout branch
id: branch
working-directory: fork-repo
run: |
BRANCH_NAME="${{ github.event.repository.name }}/publish-${{ steps.package.outputs.name }}-${{ steps.package.outputs.version }}"
echo "name=${BRANCH_NAME}" >> $GITHUB_OUTPUT
echo "Branch name: ${BRANCH_NAME}"
git fetch origin
if git show-ref --verify --quiet "refs/remotes/origin/${BRANCH_NAME}"; then
echo "action=Update" >> $GITHUB_OUTPUT
git checkout "${BRANCH_NAME}"
else
echo "action=Add" >> $GITHUB_OUTPUT
git checkout -b "${BRANCH_NAME}"
fi
# Create the package folder if it doesn't exist
- name: Create package folder
working-directory: fork-repo
run: mkdir -p "${{ steps.package.outputs.folder }}"
# Copy package files to the new folder
- name: Copy package files
run: cp -rv source-repo/src/${{ env.DAXPATTERN_NAME }}/* "fork-repo/${{ steps.package.outputs.folder }}/"
# Commit changes. If there are no changes, this will fail and stop the workflow
- name: Git commit changes
working-directory: fork-repo
run: git add -A && git commit -m "${{ steps.branch.outputs.action }} package \`${{ steps.package.outputs.name }}\` version ${{ steps.package.outputs.version }}"
# Push to upstream
- name: Git push branch
working-directory: fork-repo
run: git push origin "${{ steps.branch.outputs.name }}"
# Print summary
- name: Print summary
run: |
if [ "${{ steps.branch.outputs.action }}" == "Add" ]; then
STATUS_ICON="✅"
BADGE_COLOR="blue"
STAT_INSTRUCTIONS="Your package is ready to be published."
NEXT_INSTRUCTIONS="Click the button below to create a Pull Request and submit your package to DAX Lib:"
else
STATUS_ICON="🔄"
BADGE_COLOR="orange"
STAT_INSTRUCTIONS="Your changes have been applied and are ready for review."
NEXT_INSTRUCTIONS="If a Pull Request already exists, it has already been updated automatically. Otherwise, click the button below to create one."
fi
cat >> $GITHUB_STEP_SUMMARY << EOF
## ${STATUS_ICON} Package **\`${{ steps.package.outputs.name }}\`** version **\`${{ steps.package.outputs.version }}\`**
${STAT_INSTRUCTIONS}
## 📝 Next Step
${NEXT_INSTRUCTIONS}
[](https://github.com/${{ env.DAXLIBFORK_NAME }}/pull/new/${{ steps.branch.outputs.name }})
<details>
<summary>📋 Details (click to expand)</summary>
| | |
|---|---|
| Package name | \`${{ steps.package.outputs.name }}\` |
| Package version | \`${{ steps.package.outputs.version }}\` |
| Package folder | \`${{ steps.package.outputs.folder }}\` |
| Source | \`${{ github.repository }}\` @ \`${{ github.ref_name }}\` |
| Fork | \`${{ env.DAXLIBFORK_NAME }}\` @ \`${{ steps.branch.outputs.name }}\` |
| Create Pull Request URL | \`https://github.com/${{ env.DAXLIBFORK_NAME }}/pull/new/${{ steps.branch.outputs.name }}\` |
</details>
EOF