Build and push to store #138
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and push to store | |
on: | |
push: | |
pull_request: | |
workflow_dispatch: | |
schedule: | |
- cron: 0 5 * * 0 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
TERM: dumb | |
steps: | |
- name: Getting code | |
uses: actions/checkout@v2 | |
- name: Snapcraft build | |
uses: snapcore/action-build@v1 | |
id: snapcraft-build | |
- name: Install | |
run: | | |
set -x | |
sudo snap install --dangerous ${{ steps.snapcraft-build.outputs.snap }} | |
- name: Test basic commands | |
run: | | |
matterhorn -h | |
matterhorn -v | |
matterhorn -m -f markdown | |
matterhorn -k | |
- name: Publish | |
if: github.event_name != 'pull_request' | |
uses: snapcore/action-publish@v1 | |
env: | |
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }} | |
with: | |
snap: ${{ steps.snapcraft-build.outputs.snap }} | |
release: edge | |
- name: Promote stable versions | |
if: | | |
github.event_name != 'pull_request' && | |
(github.ref_name == 'master' || github.ref_name == 'stable') | |
env: | |
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }} | |
run: | | |
snap_file=${{ steps.snapcraft-build.outputs.snap }} | |
snap_name=$(echo "$snap_file" | grep "[a-z0-9]\+_" -o | head -1 | sed "s/_//") | |
snap_version=$(echo "$snap_file" | cut -d_ -f2) | |
if echo "$snap_file" | grep -q "[a-z0-9]\+_[0-9.]\+_.*\.snap"; then | |
echo "Stable version of $snap_name found, so let's promote it" | |
# Sleep a bit, waiting the revision to be visible | |
set -x | |
start=$EPOCHSECONDS | |
while true; do | |
sleep 1 | |
last_revision=$(snapcraft list-revisions $snap_name \ | |
--arch="$CRAFT_ARCH_TRIPLET_BUILD_FOR" 2>/dev/null | \ | |
grep -m1 -F "$snap_version" | head -n1 | cut -f1 -d ' ') | |
if [ -n "$last_revision" ]; then | |
break | |
fi | |
if (( EPOCHSECONDS-start > 40 )); then | |
echo "Can't find last snap version!" | |
exit 1 | |
fi | |
done | |
snapcraft release $snap_name $last_revision stable | |
fi |