github: Add action to create release archive (#2277)

Whenever a release is published, this action will create a release
archive and update the release body with a download section.

This also integrates the suggestions from #2276

Resolves #2276
This commit is contained in:
Patrick Ziegler 2020-12-06 18:16:17 +01:00 committed by GitHub
parent 4e576f6572
commit 1168ef36a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 110 additions and 69 deletions

103
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,103 @@
# Workflow For Releases
#
# Automatically creates and uploads a complete release archive for the given
# release.
name: Release Workflow
# Is triggered when a new release is published or by hand
# If triggered by hand, the release tag that this should target has to be
# specified.
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'Release Tag'
required: true
jobs:
upload:
runs-on: ubuntu-latest
steps:
- name: Get Version
if: ${{ github.event.inputs.tag }} != ''
run: |
if [ ${{ github.event_name }} == 'workflow_dispatch' ]; then
echo "Manual Release Triggered"
RELEASE_TAG=${{ github.event.inputs.tag }}
else
echo "Automatic Release Triggered"
RELEASE_TAG=${GITHUB_REF#refs/tags/}
fi
echo "Publishing Version $RELEASE_TAG"
echo "RELEASE_TAG=$RELEASE_TAG" >> "$GITHUB_ENV"
echo "POLYBAR_DIR=polybar-$RELEASE_TAG" >> "$GITHUB_ENV"
echo "POLYBAR_ARCHIVE=polybar-$RELEASE_TAG.tar.gz" >> "$GITHUB_ENV"
# Checks out the target tag
- uses: actions/checkout@v2
with:
ref: ${{ env.RELEASE_TAG }}
submodules: true
path: ${{ env.POLYBAR_DIR }}
- name: Create Release Archive
run: |
find "$DIR" -type d -name ".git" -exec rm -rf {} \+
tar czf "$ARCHIVE" "$DIR"
echo "SHA256SUM=$(sha256sum "$ARCHIVE" | cut -d ' ' -f 1)" >> "$GITHUB_ENV"
env:
DIR: ${{ env.POLYBAR_DIR }}
ARCHIVE: ${{ env.POLYBAR_ARCHIVE }}
- name: Get Upload URL
id: get_upload_url
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const tag = '${{ env.RELEASE_TAG }}';
console.log(`Getting Upload URL for '${tag}'`);
const release = await github.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tag
});
core.exportVariable('UPLOAD_URL', release.data.upload_url);
core.exportVariable('RELEASE_ID', release.data.id);
core.exportVariable('RELEASE_BODY', release.data.body);
- name: Upload Release Archive
id: upload_archive
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: "./${{ env.POLYBAR_ARCHIVE }}"
asset_name: ${{ env.POLYBAR_ARCHIVE }}
asset_content_type: application/gzip
# Adds a download section to the beginning of the release body
- name: Update Release Body
uses: actions/github-script@v3
env:
# Existing release body, fetched in the get_upload_url step.
RELEASE_BODY: ${{ env.RELEASE_BODY }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fname = '${{ env.POLYBAR_ARCHIVE }}'
const url = '${{ steps.upload_archive.outputs.browser_download_url }}'
const hash = '${{ env.SHA256SUM }}'
let body = "### Download:\n\n"
body += `[${fname}](${url}) (**sha256**: \`${hash}\`)\n\n`
body += process.env.RELEASE_BODY;
const release = await github.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: '${{ env.RELEASE_ID}}',
body: body
});

View File

@ -8,6 +8,7 @@ A fast and easy-to-use tool for creating status bars.
<p align="center">
<a href="https://github.com/polybar/polybar/releases"><img src="https://img.shields.io/github/release/polybar/polybar.svg"></a>
<a href="https://github.com/polybar/polybar/actions?query=workflow%3A%22Release+Workflow%22"><img src="https://github.com/polybar/polybar/workflows/Release%20Workflow/badge.svg?branch=master"></a>
<a href="https://travis-ci.com/polybar/polybar"><img src="https://travis-ci.com/polybar/polybar.svg?branch=master"></a>
<a href="https://polybar.readthedocs.io"><img src="https://readthedocs.org/projects/polybar/badge/?version=latest"></a>
<a href="https://gitter.im/polybar/polybar"><img src="https://badges.gitter.im/polybar/polybar.svg"></a>

View File

@ -1,59 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
git_url="https://github.com/polybar/polybar.git"
wd="$(realpath .)"
usage() {
cat <<EOF
Usage: $0 [-h] TAG
Creates a polybar release archive for the given git tag.
-h Print this help message
EOF
}
cleanup() {
if [ -d "$tmp_dir" ]; then
rm -rf "$tmp_dir"
fi
}
if [ $# -ne 1 ] ; then
usage
exit 1
fi
if [ "$1" = "-h" ]; then
usage
exit 0
fi
version="$1"
tmp_dir="$(mktemp -d)"
archive="$wd/polybar-${version}.tar"
trap cleanup EXIT
git clone "$git_url" "$tmp_dir/polybar"
cd "$tmp_dir/polybar"
echo "Looking for tag '$version'"
if [ "$(git tag -l "$version" | wc -l)" != "1" ]; then
echo "Tag '$version' not found"
exit 1
fi
git checkout "$version"
git submodule update --init --recursive >/dev/null
find . -type d -name ".git" -exec rm -rf {} \+
cd "$tmp_dir"
tar cf "$archive" "polybar"
sha256sum "$archive"

View File

@ -171,17 +171,13 @@ After-Release Checklist
<https://github.com/polybar/polybar/issues/1971>`_. Mention any dependency
changes and any changes to the build workflow. Also mention any new files are
created by the installation.
* Create a source archive named ``polybar-<version>.tar``.
The repository contains a script that automates this:
.. code-block:: shell
./common/release-archive.sh <version>
* Update the github release with a download section that contains a link to
``polybar-<version>.tar`` and its sha256.
* Confirm that the release archive was added to the release.
We have a GitHub action workflow called 'Release Workflow' that on every
release automatically creates a release archive, uploads it to the release,
and adds a 'Download' section to the release body.
If this fails for some reason, it should be triggered be triggered manually.
* Create a PR that updates the AUR ``PKGBUILD`` files for the ``polybar`` and
``polybar-git`` packages (push after the ``.tar`` file was created).
``polybar-git`` packages (push after the release archive is uploaded).
Deprecations