Skip to content

Commit

Permalink
Initial working version (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
R0Wi authored Sep 14, 2020
1 parent 960865e commit 67be1a0
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 1 deletion.
75 changes: 74 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,74 @@
# nextcloud-appstore-push-action
# Upload a new app version to Nextcloud's appstore
This Github Action automatically publishes a new app version in the Nextcloud appstore after you created a new Github release.

## Workflow
The following workflow will be automated by this Action:

1. Develop your app.
2. Create a new [release](https://docs.github.com/en/github/administering-a-repository/managing-releases-in-a-repository).
3. Let a new Github Workflow be triggered which automates the following steps:
- Chechout the `tag` version of your new release.
- Build a tarball for your app.
- Attach the tarball to the Github Release.
- 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.

## Prerequisites
1. **Register** you app in the Nextcloud appstore like described [here](https://nextcloudappstore.readthedocs.io/en/latest/developer.html).
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.
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*.
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).

## Usage
### Example
The following example shows how you can use this Github Action after a new Github Release was created:

```yaml
name: Build and publish app release

on:
release:
types: [published]

env:
APP_NAME: workflow_ocr

jobs:
build_and_publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
path: ${{ env.APP_NAME }}
- name: Run build
run: cd ${{ env.APP_NAME }} && make appstore
- name: Upload app tarball to release
uses: svenstaro/upload-release-action@v2
id: attach_to_release
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.APP_NAME }}/build/artifacts/appstore/${{ env.APP_NAME }}.tar.gz
asset_name: ${{ env.APP_NAME }}.tar.gz
tag: ${{ github.ref }}
overwrite: true
- name: Upload app to Nextcloud appstore
uses: R0Wi/nextcloud-appstore-push-action@v1
env:
app_name: ${{ env.APP_NAME }}
appstore_token: ${{ secrets.APPSTORE_TOKEN }}
download_url: ${{ steps.attach_to_release.outputs.browser_download_url }}
app_private_key: ${{ secrets.APP_PRIVATE_KEY }}
nightly: ${{ github.event.release.prerelease }}

```

> You'll have to store this file inside of your app's repository. For example under `.github/workflows/build_release.yml`.
### Input variables
* `app_name`: The id of your Nextcloud app *(required)*
* `appstore_token`: A valid access token to upload a new version of your app into Nextcloud appstore *(required)*
* `download_url`: The download url of you app tarball *(required)*
* `app_private_key`: The private key string of you app to sign the new release. Usually stored in Github Secrets *(required)*
* `nightly`: Controls if the app will be published as nightly into the Nextcloud appstore *(optional, default = `false`)*
### Output variables
There are currently no output variables.
33 changes: 33 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Nextcloud push app to appstore'
description: 'Push a new release of your Nextcloud app directly to the Nextcloud appstore via its REST interface.'
inputs:
app_name:
description: 'The id of your Nextcloud app'
required: true
appstore_token:
description: 'A valid access token to upload a new version of your app into Nextcloud appstore'
required: true
download_url:
description: 'The download url of you app tarball'
required: true
app_private_key:
description: 'The private key string of you app to sign the new release. Usually stored in Github Secrets'
required: true
nightly:
description: 'Controls if the app will be published as nightly into the Nextcloud appstore'
required: false
default: false
runs:
using: "composite"
steps:
- run: |
echo "${{ inputs.app_private_key }}" > "$APP_PRIVATE_KEY_FILE"
${{ github.action_path }}/push_appstore.sh
shell: bash
env:
APP_NAME: ${{ inputs.app_name }}
APPSTORE_TOKEN: ${{ inputs.appstore_token }}
NIGHTLY: ${{ inputs.nightly }}
DOWNLOAD_URL: ${{ inputs.download_url }}
APP_PRIVATE_KEY_FILE: ${{ github.workspace }}/${{ inputs.app_name }}.key
36 changes: 36 additions & 0 deletions example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build and publish app release

on:
release:
types: [published]

env:
APP_NAME: workflow_ocr

jobs:
build_and_publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
path: ${{ env.APP_NAME }}
- name: Run build
run: cd ${{ env.APP_NAME }} && make appstore
- name: Upload app tarball to release
uses: svenstaro/upload-release-action@v2
id: attach_to_release
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.APP_NAME }}/build/artifacts/appstore/${{ env.APP_NAME }}.tar.gz
asset_name: ${{ env.APP_NAME }}.tar.gz
tag: ${{ github.ref }}
overwrite: true
- name: Upload app to Nextcloud appstore
uses: R0Wi/nextcloud-appstore-push-action@v1
env:
app_name: ${{ env.APP_NAME }}
appstore_token: ${{ secrets.APPSTORE_TOKEN }}
download_url: ${{ steps.attach_to_release.outputs.browser_download_url }}
app_private_key: ${{ secrets.APP_PRIVATE_KEY }}
nightly: ${{ github.event.release.prerelease }}
17 changes: 17 additions & 0 deletions push_appstore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Used environment-variables:
# APP_NAME
# APPSTORE_TOKEN
# NIGHTLY
# DOWNLOAD_URL
# APP_PRIVATE_KEY_FILE

echo "Downloading app tarball for signing"
wget "$DOWNLOAD_URL" -O "${APP_NAME}.tar.gz"

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

echo "Creating new app release in Nextcloud appstore (nightly=${NIGHTLY})"
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} }"

0 comments on commit 67be1a0

Please sign in to comment.