-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
111 lines (94 loc) · 3.49 KB
/
action.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
102
103
104
105
106
107
108
109
110
111
name: 'Pronamic WordPress directory plugin deploy'
description: 'Deploy release to the Pronamic plugin directory.'
author: 'pronamic'
branding:
icon: 'upload-cloud'
color: 'orange'
inputs:
slug:
description: 'WordPress plugin slug.'
required: true
type: string
username:
description: 'Pronamic plugin directory username.'
required: true
type: string
password:
description: 'Pronamic plugin directory password.'
required: true
type: string
tag:
description: 'Release tag name.'
required: false
type: string
latest:
description: 'Deploy as "Latest".'
required: false
type: boolean
token:
description: 'GitHub token.'
required: false
default: ${{ github.token }}
outputs:
filename:
description: 'Filename of the plugin ZIP file.'
value: ${{ steps.prepare.outputs.filename }}
latest:
description: 'Indicates whether the release is marked as the latest.'
value: ${{ steps.prepare.outputs.latest }}
tag:
description: 'Release tag name.'
value: ${{ steps.prepare.outputs.tag }}
version:
description: 'Version of the plugin.'
value: ${{ steps.prepare.outputs.version }}
runs:
using: 'composite'
steps:
- id: 'prepare'
name: 'Prepare'
env:
GH_TOKEN: ${{ inputs.token }}
shell: bash
run: |
LATEST_RELEASE_TAG_NAME=$(gh repo view ${{ github.repository }} --json latestRelease --jq .latestRelease.tagName)
TAG=${{ inputs.tag }}
if [[ "$TAG" == "" ]]; then
TAG="$LATEST_RELEASE_TAG_NAME"
fi
VERSION=${TAG#v}
LATEST="${{ inputs.latest }}"
if [[ "$LATEST" == "" && "$LATEST_RELEASE_TAG_NAME" == "$TAG" ]]; then
LATEST="true"
fi
FILENAME="${{ inputs.slug }}.$VERSION.zip"
echo "filename=$FILENAME" >> "$GITHUB_OUTPUT"
echo "latest=$LATEST" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: 'Download GitHub release plugin ZIP file'
env:
GH_TOKEN: ${{ inputs.token }}
shell: bash
run: |
gh release download ${{ steps.prepare.outputs.tag }} --repo ${{ github.repository }} --pattern ${{ steps.prepare.outputs.filename }}
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
project_id: 'pronamic-downloads'
workload_identity_provider: 'projects/623467151959/locations/global/workloadIdentityPools/github/providers/my-repo'
- name: 'Setup Google Cloud CLI'
uses: 'google-github-actions/setup-gcloud@v2'
- name: 'Upload to Cloud Storage'
shell: bash
run: gcloud storage cp ${{ steps.prepare.outputs.filename }} gs://wp.pronamic.download/plugins/${{ inputs.slug }}/${{ steps.prepare.outputs.filename }}
- name: 'Set latest on Cloud Storage'
if: ${{ steps.prepare.outputs.latest }}
shell: bash
run: gcloud storage cp gs://wp.pronamic.download/plugins/${{ inputs.slug }}/${{ steps.prepare.outputs.filename }} gs://wp.pronamic.download/plugins/${{ inputs.slug }}/${{ inputs.slug }}.zip
- name: 'Set latest on Pronamic WordPress directory'
if: ${{ steps.prepare.outputs.latest }}
shell: bash
run: |
curl --fail-with-body --user "${{ inputs.username }}:${{ inputs.password }}" --data "version=${{ steps.prepare.outputs.version }}" --request PATCH https://wp.pronamic.directory/wp-json/pronamic-wp-extensions/v1/plugins/${{ inputs.slug }}