Skip to content

Commit bde3eaa

Browse files
authored
[ADD] Get version from /builds request (#18)
1 parent 348a1d6 commit bde3eaa

File tree

6 files changed

+32
-23
lines changed

6 files changed

+32
-23
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ To get the app id you can either navigate to your app in the App Store with your
4444
5. Enter the name of your key (e.g. `your-app-name-api-key`) and select the desired role (e.g. `Developer`).
4545
6. A new key will appear in your Keys list.
4646
7. Tap "**Download API Key**" to download the `AuthKey_{key-id}.p8` file.
47-
**Note**: You won't be able to download it afterwards.
47+
**Note**: You won't be able to download it afterwards.
4848
8. Copy **Issuer ID** and **Key ID** on the same page.
49-
**Note**: You will be able to copy them afterwards.
49+
**Note**: You will be able to copy them afterwards.
5050

5151
**Note**: It's suggested to store the sensitive information (like json web token, private key, key id and issuer id) as **[Github Secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets)** (please check also **[how to store files as secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets#storing-base64-binary-blobs-as-secrets)**).
5252

@@ -102,7 +102,7 @@ jobs:
102102
steps:
103103
- name: Checkout
104104
uses: actions/checkout@v3
105-
105+
106106
- name: Get App Store Version with iTunes Lookup
107107
id: appstore_version
108108
uses: action-tools/[email protected]
@@ -111,7 +111,7 @@ jobs:
111111
bundle-id: ${{ secrets.BUNDLE_ID }}
112112
use-https: true
113113
itunes-lookup-try-api-on-failure: false
114-
114+
115115
- name: Get App Store Version with AppStore Connect API
116116
id: appstore_version
117117
uses: action-tools/[email protected]
@@ -123,7 +123,7 @@ jobs:
123123
private-key-raw: ${{ secrets.PRIVATE_KEY_RAW }}
124124
private-key-p8-base64: ${{ secrets.PRIVATE_KEY_FILE_BASE64 }}
125125
private-key-p8-path: ./AuthKey.p8
126-
126+
127127
- name: Get results
128128
run: |
129129
echo "App Store latest version: ${{ steps.appstore_version.outputs.app-version-latest }}"
@@ -142,7 +142,7 @@ You can find some samples **[here](https://github.com/action-tools/app-latest-ve
142142
## Action Inputs
143143
144144
| Input | Required | Default | Description |
145-
| :--- | :--- | :--- | :--- |
145+
|:-----------------------------------| :--- | :--- |:--------------------------------------------------------------------------------------|
146146
| `is-itunes-lookup` | false | `false` | Should action use iTunes lookup endpoint or AppStore Connect API. |
147147
| `bundle-id` | false | | Application bundle id (required for iTunes lookup only). |
148148
| `use-https` | false | `true` | Use HTTPS or HTTP (for iTunes lookup only). |
@@ -154,6 +154,7 @@ You can find some samples **[here](https://github.com/action-tools/app-latest-ve
154154
| `private-key-p8-path` | false | | Private key file downloaded from the API Keys page in App Store Connect (\*.p8 file). |
155155
| `private-key-p8-base64` | false | | Private key downloaded from the App Store Connect (\*.p8 file) in Base64 format. |
156156
| `private-key-raw` | false | | Raw private key downloaded from the API Keys page in App Store Connect. |
157+
| `from-build` | false | | Read version of build |
157158

158159
## Action Outputs
159160

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 'App Store Connect Application Version'
22
description: 'Get latest and previous versions of application from the App Store Connect'
33
branding:
4-
icon: 'smartphone'
4+
icon: 'smartphone'
55
color: 'blue'
66
inputs:
77
is-itunes-lookup:
@@ -52,6 +52,10 @@ inputs:
5252
description: 'Number of versions to return. Maximum value is 200.'
5353
required: false
5454
default: '2'
55+
from-build:
56+
description: 'Read version from build (for App Store Connect only)'
57+
required: false
58+
default: ''
5559
outputs:
5660
app-version-latest:
5761
description: 'Latest app version'

src/index.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,23 @@ async function appstoreConnectApi() {
6969

7070
const utils = new Utils()
7171

72+
const path = core.getInput('from-build')
73+
? `/v1/builds?filter[app]=${appId}`
74+
: `/v1/apps/${appId}/appStoreVersions`;
75+
7276
const tokenString = utils.getToken(
73-
appId,
74-
issuerId,
75-
keyId,
76-
jsonWebToken,
77-
privateKeyRaw,
78-
privateKeyFilePath,
79-
privateKeyFileBase64)
77+
appId,
78+
issuerId,
79+
keyId,
80+
jsonWebToken,
81+
privateKeyRaw,
82+
privateKeyFilePath,
83+
privateKeyFileBase64,
84+
`GET ${path}`)
8085

8186
const limit = utils.getLimit(versionsLimit)
8287
console.log(messages.sending_appstore_connect_request)
83-
const jsonObject = await appstoreConnectApiRequest(appId, tokenString, limit)
88+
const jsonObject = await appstoreConnectApiRequest(path, tokenString, limit)
8489

8590
if (jsonObject.errors !== undefined && jsonObject.errors.length > 0) {
8691
const error = jsonObject.errors[0];
@@ -142,7 +147,7 @@ function setOutput(data, index) {
142147
throw new Error(message)
143148
}
144149

145-
const version = attributes.versionString
150+
const version = attributes.versionString ?? attributes.version
146151
const state = attributes.appStoreState
147152
const releaseType = attributes.releaseType
148153
const createdDate = attributes.createdDate

src/request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fetch from 'node-fetch'
22

3-
export const appstoreConnectApiRequest = async (appId, jwt, limit) => {
4-
const url = `https://api.appstoreconnect.apple.com/v1/apps/${appId}/appStoreVersions?limit=${limit}`
3+
export const appstoreConnectApiRequest = async (path, jwt, limit) => {
4+
const url = `https://api.appstoreconnect.apple.com${path}?limit=${limit}`
55
const response = await fetch(url, { headers: { 'Authorization': `Bearer ${jwt}` } })
66
return await response.json()
77
}

src/token.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@ export default class Token {
1616
const keyFilename = 'authkey.p8'
1717
const buffer = Buffer.from(keyFileBase64, 'base64')
1818
fs.writeFileSync(keyFilename, buffer)
19-
this.privateKey = fs.readFileSync(keyFilename)
19+
this.privateKey = fs.readFileSync(keyFilename)
2020
console.log(messages.using_base64_private_key)
2121
} else {
2222
throw new Error(messages.appstore_connect_setup_error)
2323
}
2424
}
2525

26-
generate(appId, issuerId, keyId) {
26+
generate(appId, issuerId, keyId, scope) {
2727
const exp = '20m'
2828
const alg = 'ES256'
2929
const aud = 'appstoreconnect-v1'
30-
const scope = `GET /v1/apps/${appId}/appStoreVersions`
3130
const payload = { iss: issuerId, aud: aud, scope: [scope] }
3231
const jwtOptions = { expiresIn: exp, algorithm: alg, header: { kid: keyId } }
3332
return jwt.sign(payload, this.privateKey, jwtOptions)

src/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default class Utils {
88
this.defaultLimit = 2
99
}
1010

11-
getToken(appId, issuerId, keyId, jwt, pkRaw, pkFilePath, pkFileBase64) {
11+
getToken(appId, issuerId, keyId, jwt, pkRaw, pkFilePath, pkFileBase64, scope) {
1212
if (!!jwt) {
1313
console.log(messages.predefined_jwt_set)
1414
return jwt
@@ -18,7 +18,7 @@ export default class Utils {
1818
console.log(messages.setting_private_key)
1919
const token = new Token(pkRaw, pkFilePath, pkFileBase64)
2020
console.log(messages.automatic_token_generation)
21-
return token.generate(appId, issuerId, keyId)
21+
return token.generate(appId, issuerId, keyId, scope)
2222
}
2323

2424
getLimit(limitInput) {

0 commit comments

Comments
 (0)