-
Notifications
You must be signed in to change notification settings - Fork 1
99 lines (80 loc) · 3 KB
/
deploy-php-package.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
name: Deploy PHP Package
on:
release:
types: [published]
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
deploy:
name: Deploy PHP Package
needs: [details]
runs-on: ubuntu-latest
if: ${{ fromJson(needs.details.outputs.result).shouldDeploy }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.ACCESS_TOKEN_IR }}
- name: Setup Environment
uses: ./actions/setup
- name: Prepare
run: |
# Change dir to the package
cd ${{ fromJson(needs.details.outputs.result).path }}
# Create a temp dir and move the files to it
mkdir -p temp
# Move only the files that are needed
mv -t temp/ composer.json src/ LICENSE README.md CHANGELOG.md .gitignore
# Reset pwd
cd -
- name: Deploy to repo
uses: manzoorwanijk/action-deploy-to-repo@v3
with:
src_dir: ${{ fromJson(needs.details.outputs.result).path }}/temp
target_repo: ${{ fromJson(needs.details.outputs.result).repo }}
target_dir: "."
target_branch: main
access_token: ${{ secrets.ACCESS_TOKEN_IR }}
# Remove everything from the target repo before deploying
cleanup_command: git rm -rf . && git clean -fxd
git_user_email: ${{ secrets.GIT_USER_EMAIL_IR }}
git_user_name: ${{ secrets.GIT_USER_NAME_IR }}
- name: Release
uses: softprops/action-gh-release@v1
with:
body: ${{ github.event.release.body }}
token: ${{ secrets.ACCESS_TOKEN_IR }}
tag_name: v${{ fromJson(needs.details.outputs.result).version }}
repository: ${{ fromJson(needs.details.outputs.result).repo }}
details:
name: Get details
runs-on: ubuntu-latest
outputs:
result: ${{ steps.details.outputs.result }}
steps:
- name: Get details
uses: actions/github-script@v7
id: details
with:
script: |
const tagRegex = /^(?<name>.+)@(?<version>[^@]+)$/;
const result = '${{ github.event.release.tag_name }}'.match(tagRegex);
if (!result?.groups?.name || !result?.groups?.version) {
console.warn('Invalid tag name: "${{ github.event.release.tag_name }}"');
return { shouldDeploy: false };
}
const { name, version } = result.groups;
const toDeploy = [
'@wpsocio/telegram-format-text',
'@wpsocio/wp-utils',
'@wpsocio/wptelegram-bot-api',
];
if (!toDeploy.includes(name)) {
return { shouldDeploy: false };
}
const path = `packages/php/${name.split('/', 2)[1]}/`;
const shouldDeploy = true;
const repo = name.replace('@', '');
return { name, version, path, repo, shouldDeploy };
- name: Print details
run: |
echo "Details: ${{ steps.details.outputs.result }}"