From 1168ef36a0ed24a90f53c576c7a7b576e8dd6921 Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Sun, 6 Dec 2020 18:16:17 +0100 Subject: [PATCH] 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 --- .github/workflows/release.yml | 103 ++++++++++++++++++++++++++++++++++ README.md | 1 + common/release-archive.sh | 59 ------------------- doc/dev/release-workflow.rst | 16 ++---- 4 files changed, 110 insertions(+), 69 deletions(-) create mode 100644 .github/workflows/release.yml delete mode 100755 common/release-archive.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..3fdc6a85 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 + }); diff --git a/README.md b/README.md index 0ff03acc..c4c0434f 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ A fast and easy-to-use tool for creating status bars.

+ diff --git a/common/release-archive.sh b/common/release-archive.sh deleted file mode 100755 index 222dc570..00000000 --- a/common/release-archive.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -git_url="https://github.com/polybar/polybar.git" -wd="$(realpath .)" - -usage() { - cat </dev/null - -find . -type d -name ".git" -exec rm -rf {} \+ - -cd "$tmp_dir" -tar cf "$archive" "polybar" -sha256sum "$archive" diff --git a/doc/dev/release-workflow.rst b/doc/dev/release-workflow.rst index faeb1d2f..54e21146 100644 --- a/doc/dev/release-workflow.rst +++ b/doc/dev/release-workflow.rst @@ -171,17 +171,13 @@ After-Release Checklist `_. 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-.tar``. - The repository contains a script that automates this: - -.. code-block:: shell - - ./common/release-archive.sh - -* Update the github release with a download section that contains a link to - ``polybar-.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