Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
snap release with appstream metainfo (#12)
Browse files Browse the repository at this point in the history
- update artifact name with release tag
  • Loading branch information
yakkle authored Sep 30, 2021
1 parent 92608e5 commit 0b2cd44
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 10 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/snap_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,44 @@ on:
description: 'upload artifact'
required: true
default: 'yes'
release_tag:
description: 'release tag'
required: true
default: '20210928.0'
jobs:
release:
runs-on: ubuntu-latest
env:
UPLOAD_ARTIFACT: ${{ github.event.inputs.upload_artifact }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
ARTIFACT_NAME: loopchain_snap
DEBUG: ${{ true }}
steps:
- name: Checkout release
uses: actions/checkout@v2
- name: Set envs
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo "env.RELEASE_TAG: (${{ env.RELEASE_TAG }})"
RELEASE_VERSION=${{ github.event.inputs.release_tag }}
echo "RELEASE_TAG=$RELEASE_VERSION" >> $GITHUB_ENV
echo "release tag: ($RELEASE_VERSION)"
if [[ -n $RELEASE_VERSION ]]; then
echo "ARTIFACT_NAME=loopchain_snap_$RELEASE_VERSION" >> $GITHUB_ENV
fi
- name: Check environment variables
if : ${{ env.DEBUG }}
run: |
echo $PWD
echo "upload artifact: ($UPLOAD_ARTIFACT)"
echo "release tag: ($RELEASE_TAG)"
echo "artifact name: ($ARTIFACT_NAME)"
echo "deubg: ($DEBUG)"
echo "release tag empty: (${{ env.RELEASE_TAG == '' }})"
- name: Create metadata
run: |
APPSTREAM_PATH=$(python3 -c "import asset; print(asset.metadata('$RELEASE_TAG'))")
cat $APPSTREAM_PATH
- name: Build snapcraft
id: snapcraft
uses: snapcore/action-build@v1
Expand All @@ -38,10 +58,10 @@ jobs:
if: ${{ env.UPLOAD_ARTIFACT == 'yes' }}
uses: actions/upload-artifact@v2
with:
name: loopchain_snap
name: ${{ env.ARTIFACT_NAME }}
path: ${{ steps.snapcraft.outputs.snap }}
- name: Publish to snap store
if: ${{ success() && env.RELEASE_TAG != '' }}
if: ${{ success() && github.event_name == 'release' && env.RELEASE_TAG != '' }}
uses: snapcore/action-publish@v1
with:
store_login: ${{ secrets.STORE_LOGIN }}
Expand Down
12 changes: 12 additions & 0 deletions appstream.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="console-application">
<id>org.iconrepublic.loopchain</id>
<name>$NAME</name>
<summary>$SUMMARY</summary>
<description>
loopchain-citizen is software that loopchain client excluded vote function.
</description>
<releases>
<release date="$DATE" version="$VERSION"/>
</releases>
</component>
35 changes: 34 additions & 1 deletion asset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytz
from datetime import datetime
from string import Template


def docker_tag() -> str:
import pytz
tzinfo = pytz.timezone("Asia/Seoul")
# hash_tag = "${{ hashFiles('Makefile') }}"
# print(hash_tag)
Expand All @@ -17,3 +18,35 @@ def package_info(file_path: str) -> str:

# https://git.io/JkD3W
return f"PACKAGE_INFO_BODY<<EOF\n{body}\nEOF"


def metadata(tag: str) -> str:
with open("./appstream.template", "r") as f:
template = f.read()

import re
import os
from pathlib import Path
from datetime import datetime

release_date = re.sub(r"\.\d+$", "", tag)
release_date = datetime.strptime(release_date, "%Y%m%d")
appstream_data = {
"NAME": "loopchain",
"SUMMARY": "loopchain citizen",
"DATE": f"{release_date:%Y-%m-%d}",
"VERSION": tag
}
t = Template(template)
appstream = t.substitute(appstream_data)

appstream_path: Path = Path("./snap/local/org.iconrepublic.loopchain.appdata.xml")
try:
appstream_path.parent.mkdir()
except FileExistsError:
pass

with open(appstream_path, "w") as f:
f.write(appstream)

return os.fspath(appstream_path)
9 changes: 2 additions & 7 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: loopchain
type: app
adopt-info: loopchain
summary: loopchain citizen
description: |
loopchain-citizen is software that loopchain client excluded vote function.
confinement: strict
base: core18

Expand Down Expand Up @@ -104,14 +101,11 @@ parts:
python-version: python3
source-type: git
source: https://github.com/icon-project/loopchain.git
parse-info: [$SNAPCRAFT_PROJECT_DIR/snap/local/org.iconrepublic.loopchain.appdata.xml]
override-pull: |
snapcraftctl pull
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
git checkout ${LATEST_TAG}
VERSION=$(curl -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/icon-project/icon-release/releases/latest | jq -r .tag_name)
echo "release version : ${VERSION}"
snapcraftctl set-version ${VERSION}
snapcraftctl set-grade stable
override-build: |
snapcraftctl build
Expand All @@ -135,6 +129,7 @@ parts:
apps:
loopchain:
command: bin/snapcraft-preload $SNAP/bin/loopchain
common-id: org.iconrepublic.loopchain
plugs:
- home
- network
Expand Down

0 comments on commit 0b2cd44

Please sign in to comment.