Skip to content

Commit 294fe91

Browse files
authored
Merge master into stable (#4)
* Update tags automatically * Allow username + password for NC appstore authentication (#3) * Add username pw auth and tests * Curl fail on non 200 * Fail script on error * Try fix function not found error * Source * Basics for testing * Add more tests * Update readme (username + password)
1 parent ecf1b8a commit 294fe91

File tree

14 files changed

+691
-20
lines changed

14 files changed

+691
-20
lines changed

.github/workflows/test.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Run tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
runtests:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2
13+
- name: Install test environment
14+
run: sudo apt-get update && sudo apt-get -y install bats nodejs npm
15+
- name: Install node dependencies
16+
run: cd test && npm install
17+
- name: Run tests
18+
run: cd test && chmod +x run_tests.sh && ./run_tests.sh

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test/node_modules
2+
test/test_app.tar.gz
3+
test/server_output.txt

README.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,31 @@
22
This Github Action automatically publishes a new app version in the Nextcloud appstore after you created a new Github release.
33

44
## Workflow
5-
The following workflow will be automated by this Action:
5+
The following workflow can be automated when using this Github Action:
66

7-
1. Develop your app.
8-
2. Create a new [release](https://docs.github.com/en/github/administering-a-repository/managing-releases-in-a-repository).
9-
3. Let a new Github Workflow be triggered which automates the following steps:
7+
1. Create a new [release](https://docs.github.com/en/github/administering-a-repository/managing-releases-in-a-repository) of your app in Github.
8+
2. Let a new Github Workflow be triggered which automates the following steps:
109
- Chechout the `tag` version of your new release.
1110
- Build a tarball for your app.
1211
- Attach the tarball to the Github Release.
13-
- Upload a new app version into the Nextcloud appstore referencing your attached tarball. This includes creating a signature and authenticating against Nextcloud's appstore via token.
12+
- Upload a new app version into the Nextcloud appstore referencing your attached tarball. This includes creating a signature and authenticating against Nextcloud's appstore via token (or username and password).
1413

1514
## Prerequisites
1615
1. **Register** you app in the Nextcloud appstore like described [here](https://nextcloudappstore.readthedocs.io/en/latest/developer.html).
17-
2. Paste the content of your app's **private key into a new [Github Secret](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets)** of your app's repository (e.g. with the key `APP_PRIVATE_KEY`). This key is later used for signing the new app version before uploading it to the appstore.
18-
3. Create a new [Github Secret](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) for your **Nextcloud appstore account [token](https://nextcloudappstore.readthedocs.io/en/latest/restapi.html#authentication)** (e.g. with the key `APPSTORE_TOKEN`). The token can be copied by logging into https://apps.nextcloud.com an then visiting *My account -> API-Token*.
19-
4. Make sure you are able to build a tarball for your app inside of Github actions. This could be achieved by using an appropriate [`Makefile`](https://github.com/nextcloud/files_photospheres/blob/master/Makefile).
16+
2. Paste the content of your app's **private key into a new [Github Secret](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets)** named `APP_PRIVATE_KEY`. This key is later used for signing the new app version before uploading it to the appstore.
17+
18+
3. For **authentication** against the Nextcloud appstore you can use one of the following approaches:
19+
1. **Token** (recommended): create a new [Github Secret](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) for your Nextcloud appstore account [token](https://nextcloudappstore.readthedocs.io/en/latest/restapi.html#authentication) named `APPSTORE_TOKEN`. The token can be copied by logging into https://apps.nextcloud.com an then visiting *My account -> API-Token*.
20+
2. **Username & password**: create two [Github Secrets](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) `APPSTORE_USERNAME` and `APPSTORE_PASSWORD` holding your personal login information for the [Nextcloud appstore](https://apps.nextcloud.com). Make sure this user is allowed to create new app releases for you app.
21+
4. Make sure you are able to build a tarball for your app inside of Github actions. This could be achieved by using an appropriate `Makefile`. Here are two examples:
22+
* https://github.com/nextcloud/files_photospheres/blob/master/Makefile (without [code signing](https://docs.nextcloud.com/server/latest/admin_manual/issues/code_signing.html))
23+
* https://github.com/nextcloud/spreed/blob/b5198c2d0d9cdc2c7c0e410867d2ec84336e23a6/Makefile (with [code signing](https://docs.nextcloud.com/server/latest/admin_manual/issues/code_signing.html))
2024

2125
## Usage
22-
### Example
23-
The following example shows how you can use this Github Action after a new Github Release was created:
26+
In general you'll have to create a new `.yml`-file in your app's repository inside of `.github/workflows` (for example `.github/workflows/build_release.yml`) to use this Github Action. The following sections list a few useful examples on how you can combine this Action with others to automate your workflow. All samples can also be found in the [`examples`](examples) directory of this repository.
27+
28+
### Example without [code signing](https://docs.nextcloud.com/server/latest/admin_manual/issues/code_signing.html)
29+
The following example shows how you can use this Github Action with your Nextcloud Appstore token after a new Github Release was created:
2430

2531
```yaml
2632
name: Build and publish app release
@@ -62,13 +68,18 @@ jobs:
6268

6369
```
6470

65-
> You'll have to store this file inside of your app's repository. For example under `.github/workflows/build_release.yml`.
66-
6771
### Input variables
68-
* `app_name`: The id of your Nextcloud app *(required)*
69-
* `appstore_token`: A valid access token to upload a new version of your app into Nextcloud appstore *(required)*
70-
* `download_url`: The download url of you app tarball *(required)*
71-
* `app_private_key`: The private key string of you app to sign the new release. Usually stored in Github Secrets *(required)*
72-
* `nightly`: Controls if the app will be published as nightly into the Nextcloud appstore *(optional, default = `false`)*
72+
| Name | Description | Default | Possible values | Required |
73+
|-------------------|---------------------------------------------------------------------------------------------|---------|-----------------|----------|
74+
| `app_name` | The id of your Nextcloud app | - | `string` | `true` |
75+
| `appstore_token` | A valid access token to upload a new version of your app into Nextcloud appstore | - | `string` | `false`* |
76+
| `appstore_username` | Username for Nextcloud appstore | - | `string` | `false`* |
77+
| `appstore_password` | Password for Nextcloud appstore | - | `string` | `false`* |
78+
| `download_url` | The download url of you app tarball | - | `string` | `true` |
79+
| `app_private_key` | The private key string of you app to sign the new release. Usually stored in Github Secrets | - | `string` | `true` |
80+
| `nightly` | Controls if the app will be published as nightly into the Nextcloud appstore | `false` | `true`, `false` | `false` |
81+
82+
> *Either `appstore_token` or `appstore_username` **and** `appstore_password` must be set.
83+
7384
### Output variables
7485
There are currently no output variables.

action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ inputs:
66
required: true
77
appstore_token:
88
description: 'A valid access token to upload a new version of your app into Nextcloud appstore'
9-
required: true
9+
required: false
10+
appstore_username:
11+
description: 'Username for Nextcloud appstore'
12+
required: false
13+
appstore_password:
14+
description: 'Password for Nextcloud appstore'
15+
required: false
1016
download_url:
1117
description: 'The download url of you app tarball'
1218
required: true
@@ -27,6 +33,8 @@ runs:
2733
env:
2834
APP_NAME: ${{ inputs.app_name }}
2935
APPSTORE_TOKEN: ${{ inputs.appstore_token }}
36+
APPSTORE_USERNAME: ${{ inputs.appstore_username }}
37+
APPSTORE_PASSWORD: ${{ inputs.appstore_password }}
3038
NIGHTLY: ${{ inputs.nightly }}
3139
DOWNLOAD_URL: ${{ inputs.download_url }}
3240
APP_PRIVATE_KEY_FILE: ${{ github.workspace }}/${{ inputs.app_name }}.key

functions.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# $1 = private key file
4+
# $2 = app tar file
5+
function createsign {
6+
echo "`openssl dgst -sha512 -sign $1 $2 | openssl base64 -A`"
7+
}

push_appstore.sh

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
11
#!/bin/bash
2+
set -eo pipefail
23

34
# Used environment-variables:
45
# APP_NAME
56
# APPSTORE_TOKEN
7+
# APPSTORE_USERNAME
8+
# APPSTORE_PASSWORD
69
# NIGHTLY
710
# DOWNLOAD_URL
811
# APP_PRIVATE_KEY_FILE
912

13+
script_dir="$(dirname "$0")"
14+
appstore_url=$APPSTORE_URL || "https://apps.nextcloud.com/api/v1/apps/releases"
15+
16+
. "${script_dir}/functions.sh"
17+
1018
echo "Downloading app tarball for signing"
1119
wget "$DOWNLOAD_URL" -O "${APP_NAME}.tar.gz"
1220

1321
echo "Creating signature for app release"
14-
sign="`openssl dgst -sha512 -sign ${APP_PRIVATE_KEY_FILE} ${APP_NAME}.tar.gz | openssl base64 -A`"
22+
sign="`createsign ${APP_PRIVATE_KEY_FILE} ${APP_NAME}.tar.gz`"
1523

1624
echo "Creating new app release in Nextcloud appstore (nightly=${NIGHTLY})"
17-
curl -X POST https://apps.nextcloud.com/api/v1/apps/releases -H "Authorization: Token ${APPSTORE_TOKEN}" -H "Content-Type: application/json" -d "{\"download\":\"${DOWNLOAD_URL}\", \"signature\": \"${sign}\", \"nightly\": ${NIGHTLY} }"
25+
26+
if [ ! -z $APPSTORE_TOKEN ]
27+
then
28+
echo "Using token authentication"
29+
curl -s --fail --show-error -X POST $appstore_url -H "Authorization: Token ${APPSTORE_TOKEN}" -H "Content-Type: application/json" -d "{\"download\": \"${DOWNLOAD_URL}\", \"signature\": \"${sign}\", \"nightly\": ${NIGHTLY} }"
30+
elif [ ! -z $APPSTORE_USERNAME ] && [ ! -z $APPSTORE_PASSWORD ]
31+
then
32+
echo "Using username password authentication"
33+
curl -s --fail --show-error -X POST $appstore_url -u "${APPSTORE_USERNAME}:${APPSTORE_PASSWORD}" -H "Content-Type: application/json" -d "{\"download\": \"${DOWNLOAD_URL}\", \"signature\": \"${sign}\", \"nightly\": ${NIGHTLY} }"
34+
else
35+
echo "Authentication cannot be done. Please provide 'appstore_token' or 'appstore_username' and 'appstore_password' input variables."
36+
exit 1
37+
fi

0 commit comments

Comments
 (0)