Skip to content

Commit 703f445

Browse files
Alexey PortnovAlexey Portnov
authored andcommitted
CI: локальный build.yml вместо reusable workflow — поддержка secrets для OAuth
1 parent b418cf6 commit 703f445

File tree

1 file changed

+106
-34
lines changed

1 file changed

+106
-34
lines changed

.github/workflows/build.yml

Lines changed: 106 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,128 @@ on:
77
- develop
88
workflow_dispatch:
99

10-
env:
11-
AMO_CLIENT_ID: ${{ secrets.AMO_CLIENT_ID }}
12-
AMO_CLIENT_SECRET: ${{ secrets.AMO_CLIENT_SECRET }}
13-
AMO_REDIRECT_URL: ${{ secrets.AMO_REDIRECT_URL }}
10+
permissions:
11+
contents: write
12+
packages: write
1413

1514
jobs:
16-
build:
17-
uses: mikopbx/.github-workflows/.github/workflows/extension-publish.yml@master
18-
with:
19-
initial_version: "1.84"
20-
custom_build_steps: |
21-
cd module
22-
sed -i "s|%CLIENT_ID%|${{ env.AMO_CLIENT_ID }}|g" Lib/AmoCrmMainBase.php
23-
sed -i "s|%CLIENT_SECRET%|${{ env.AMO_CLIENT_SECRET }}|g" Lib/AmoCrmMainBase.php
24-
sed -i "s|%REDIRECT_URL%|${{ env.AMO_REDIRECT_URL }}|g" Lib/AmoCrmMainBase.php
25-
echo "AmoCrmMainBase.php placeholders replaced."
26-
WIDGET_VERSION="1.0.$(git rev-list --count HEAD)"
27-
sed -i "s|%WidgetVersion%|$WIDGET_VERSION|g" widget/manifest.json
28-
sed -i "s|%WidgetVersion%|$WIDGET_VERSION|g" widget/script.js
29-
cd widget && zip -r "$RUNNER_TEMP/widget.zip" . -x "*.DS_Store*" && cd ..
30-
echo "Widget built: widget.zip (version $WIDGET_VERSION)"
31-
rm -rf widget
32-
echo "widget/ removed from module archive."
33-
secrets: inherit
34-
35-
upload-widget:
36-
needs: build
15+
build-and-publish:
3716
runs-on: ubuntu-latest
38-
permissions:
39-
contents: write
4017
steps:
41-
- uses: actions/checkout@v4
18+
- name: Checkout module repository
19+
uses: actions/checkout@v4
4220
with:
4321
fetch-depth: 0
22+
path: module
23+
24+
- name: Checkout workflows repository
25+
uses: actions/checkout@v4
26+
with:
27+
repository: mikopbx/.github-workflows
28+
path: .github-workflows
29+
30+
- name: Validate module configuration
31+
id: validate
32+
uses: ./.github-workflows/.github/actions/validate
33+
34+
- name: Manage versions
35+
id: version
36+
uses: ./.github-workflows/.github/actions/versioning
37+
with:
38+
initial_version: "1.84"
39+
40+
- name: Setup build environment
41+
uses: ./.github-workflows/.github/actions/docker-build
42+
with:
43+
php_version: ${{ steps.validate.outputs.php_version }}
44+
45+
- name: Handle dependencies
46+
uses: ./.github-workflows/.github/actions/composer
47+
with:
48+
php_version: ${{ steps.validate.outputs.php_version }}
49+
50+
- name: Cache Docker images
51+
uses: actions/cache@v3
52+
id: docker-cache
53+
with:
54+
path: ${{ runner.temp }}/docker-cache-*.tar
55+
key: ${{ runner.os }}-docker-${{ hashFiles('module/**/Dockerfile') }}
56+
restore-keys: |
57+
${{ runner.os }}-docker-
58+
59+
- name: Replace OAuth placeholders
60+
env:
61+
AMO_CLIENT_ID: ${{ secrets.AMO_CLIENT_ID }}
62+
AMO_CLIENT_SECRET: ${{ secrets.AMO_CLIENT_SECRET }}
63+
AMO_REDIRECT_URL: ${{ secrets.AMO_REDIRECT_URL }}
64+
run: |
65+
cd module
66+
sed -i "s|%CLIENT_ID%|$AMO_CLIENT_ID|g" Lib/AmoCrmMainBase.php
67+
sed -i "s|%CLIENT_SECRET%|$AMO_CLIENT_SECRET|g" Lib/AmoCrmMainBase.php
68+
sed -i "s|%REDIRECT_URL%|$AMO_REDIRECT_URL|g" Lib/AmoCrmMainBase.php
69+
echo "AmoCrmMainBase.php placeholders replaced."
4470
4571
- name: Build widget
4672
run: |
73+
cd module
4774
WIDGET_VERSION="1.0.$(git rev-list --count HEAD)"
4875
sed -i "s|%WidgetVersion%|$WIDGET_VERSION|g" widget/manifest.json
4976
sed -i "s|%WidgetVersion%|$WIDGET_VERSION|g" widget/script.js
50-
cd widget && zip -r ../widget.zip . -x "*.DS_Store*"
77+
cd widget && zip -r "$RUNNER_TEMP/widget.zip" . -x "*.DS_Store*" && cd ..
78+
echo "Widget built: widget.zip (version $WIDGET_VERSION)"
79+
rm -rf widget
80+
echo "widget/ removed from module archive."
81+
82+
- name: Sync translations from Core
83+
uses: ./.github-workflows/.github/actions/sync-translations
84+
85+
- name: Create module package
86+
id: archive
87+
uses: ./.github-workflows/.github/actions/archive
88+
with:
89+
version: ${{ steps.version.outputs.new_version }}
90+
91+
- name: Generate changelog
92+
id: changelog
93+
if: steps.validate.outputs.changelog_enabled == 'true'
94+
uses: ./.github-workflows/.github/actions/changelog
95+
96+
- name: Publish module
97+
if: |
98+
github.ref == 'refs/heads/master' &&
99+
steps.validate.outputs.publish_release == 'true'
100+
env:
101+
OWNCLOUD_AUTH: ${{ secrets.OWNCLOUD_AUTH }}
102+
WEBDAV_ROOT: ${{ secrets.WEBDAV_ROOT }}
103+
SHARE_API_URL: ${{ secrets.SHARE_API_URL }}
104+
MIKO_LIC_REST_VENDOR_ID: ${{ secrets.MIKO_LIC_REST_VENDOR_ID }}
105+
MIKO_LIC_REST_API_KEY: ${{ secrets.MIKO_LIC_REST_API_KEY }}
106+
MIKO_LIC_HOSTNAME: ${{ secrets.MIKO_LIC_HOSTNAME }}
107+
uses: ./.github-workflows/.github/actions/publish
108+
with:
109+
php_version: ${{ steps.validate.outputs.php_version }}
110+
module_filename: ${{ steps.archive.outputs.filename }}
111+
version: ${{ steps.version.outputs.new_version }}
112+
changelog: ${{ steps.changelog.outputs.changelog }}
113+
114+
- name: Manage GitHub releases
115+
if: steps.validate.outputs.create_github_release == 'true'
116+
uses: ./.github-workflows/.github/actions/release
117+
with:
118+
version: ${{ steps.version.outputs.new_version }}
119+
version_tag: ${{ steps.version.outputs.new_version_tag }}
120+
module_filename: ${{ steps.archive.outputs.filename }}
121+
changelog: ${{ steps.changelog.outputs.changelog }}
51122

52-
- name: Upload widget to GitHub release
123+
- name: Upload widget to release
124+
if: steps.validate.outputs.create_github_release == 'true'
53125
env:
54126
GH_TOKEN: ${{ github.token }}
55127
run: |
56-
TAG=$(gh release list --limit 1 --json tagName -q '.[0].tagName')
57-
if [ -n "$TAG" ]; then
58-
gh release upload "$TAG" widget.zip --clobber
128+
TAG="${{ steps.version.outputs.new_version_tag }}"
129+
if [ -n "$TAG" ] && gh release view "$TAG" &>/dev/null; then
130+
gh release upload "$TAG" "$RUNNER_TEMP/widget.zip" --clobber
59131
echo "widget.zip uploaded to release $TAG"
60132
else
61-
echo "No release found, skipping upload."
133+
echo "Release $TAG not found, skipping widget upload."
62134
fi

0 commit comments

Comments
 (0)