Skip to content

Commit

Permalink
Enable creation of full, offline binary releases (w/dependencies) (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6675636b796f75676974687562 authored Nov 14, 2022
1 parent 18bfc2e commit ec8e5f2
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 41 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/bindist-full.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Create a binary distribution (full)

on:
workflow_call:
inputs:
release-version:
required: true
type: string

jobs:
dist:
name: Binary distribution (full)
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- id: filenames
name: Archive names
run: |
echo "diktat-cli-tar=diktat-cli-${{ inputs.release-version }}-full.tar" >>"${GITHUB_OUTPUT}"
echo "diktat-cli-tgz=diktat-cli-${{ inputs.release-version }}-full.tar.gz" >>"${GITHUB_OUTPUT}"
echo "diktat-cli-zip=diktat-cli-${{ inputs.release-version }}-full.zip" >>"${GITHUB_OUTPUT}"
shell: bash

- uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 17

- name: Download dependencies
run: |
bin/diktat --no-download-progress -V
env:
GITHUB_TOKEN: ${{ github.token }}
shell: bash

- name: Archive
run: |
tar cf '${{ steps.filenames.outputs.diktat-cli-tar }}' --exclude-backups --exclude-vcs --exclude-vcs-ignore --exclude='*.bat' --exclude='*.cmd' -C bin .
gzip -9 '${{ steps.filenames.outputs.diktat-cli-tar }}'
zip -jrX9 -Z bzip2 '${{ steps.filenames.outputs.diktat-cli-zip }}' bin
shell: bash

# Upload a .tar.gz artifact, except when this is a release.
- name: Upload ${{ steps.filenames.outputs.diktat-cli-tgz }}
if: ${{ github.ref_type == 'branch' }}
uses: actions/upload-artifact@v3
with:
name: ${{ steps.filenames.outputs.diktat-cli-tgz }}
path: ${{ steps.filenames.outputs.diktat-cli-tgz }}
if-no-files-found: error
retention-days: 1

# Upload a .zip artifact, except when this is a release.
- name: Upload ${{ steps.filenames.outputs.diktat-cli-zip }}
if: ${{ github.ref_type == 'branch' }}
uses: actions/upload-artifact@v3
with:
name: ${{ steps.filenames.outputs.diktat-cli-zip }}
path: ${{ steps.filenames.outputs.diktat-cli-zip }}
if-no-files-found: error
retention-days: 1

- id: create_release
if: ${{ github.ref_type == 'tag' }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
tag_name: ${{ github.ref }}
release_name: v${{ inputs.release-version }}
draft: false
prerelease: false

- name: Upload release asset (${{ steps.filenames.outputs.diktat-cli-tgz }})
id: upload-release-asset-tgz
if: ${{ github.ref_type == 'tag' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.filenames.outputs.diktat-cli-tgz }}
asset_name: ${{ steps.filenames.outputs.diktat-cli-tgz }}
asset_content_type: application/gzip

- name: Upload release asset (${{ steps.filenames.outputs.diktat-cli-zip }})
id: upload-release-asset-zip
if: ${{ github.ref_type == 'tag' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.filenames.outputs.diktat-cli-zip }}
asset_name: ${{ steps.filenames.outputs.diktat-cli-zip }}
asset_content_type: application/zip
86 changes: 86 additions & 0 deletions .github/workflows/bindist-thin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Create a binary distribution (thin)

on:
workflow_call:
inputs:
release-version:
required: true
type: string

jobs:
dist:
name: Binary distribution (thin)
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- id: filenames
name: Archive names
run: |
echo "diktat-cli-tar=diktat-cli-${{ inputs.release-version }}.tar" >>"${GITHUB_OUTPUT}"
echo "diktat-cli-tgz=diktat-cli-${{ inputs.release-version }}.tar.gz" >>"${GITHUB_OUTPUT}"
echo "diktat-cli-zip=diktat-cli-${{ inputs.release-version }}.zip" >>"${GITHUB_OUTPUT}"
shell: bash

- name: Archive
run: |
tar cf '${{ steps.filenames.outputs.diktat-cli-tar }}' --exclude-backups --exclude-vcs --exclude-vcs-ignore --exclude='*.bat' --exclude='*.cmd' -C bin diktat
gzip -9 '${{ steps.filenames.outputs.diktat-cli-tar }}'
zip -jrX9 -Z bzip2 '${{ steps.filenames.outputs.diktat-cli-zip }}' bin
shell: bash

# Upload a .tar.gz artifact, except when this is a release.
- name: Upload ${{ steps.filenames.outputs.diktat-cli-tgz }}
if: ${{ github.ref_type == 'branch' }}
uses: actions/upload-artifact@v3
with:
name: ${{ steps.filenames.outputs.diktat-cli-tgz }}
path: ${{ steps.filenames.outputs.diktat-cli-tgz }}
if-no-files-found: error
retention-days: 1

# Upload a .zip artifact, except when this is a release.
- name: Upload ${{ steps.filenames.outputs.diktat-cli-zip }}
if: ${{ github.ref_type == 'branch' }}
uses: actions/upload-artifact@v3
with:
name: ${{ steps.filenames.outputs.diktat-cli-zip }}
path: ${{ steps.filenames.outputs.diktat-cli-zip }}
if-no-files-found: error
retention-days: 1

- id: create_release
if: ${{ github.ref_type == 'tag' }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
tag_name: ${{ github.ref }}
release_name: v${{ inputs.release-version }}
draft: false
prerelease: false

- name: Upload release asset (${{ steps.filenames.outputs.diktat-cli-tgz }})
id: upload-release-asset-tgz
if: ${{ github.ref_type == 'tag' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.filenames.outputs.diktat-cli-tgz }}
asset_name: ${{ steps.filenames.outputs.diktat-cli-tgz }}
asset_content_type: application/gzip

- name: Upload release asset (${{ steps.filenames.outputs.diktat-cli-zip }})
id: upload-release-asset-zip
if: ${{ github.ref_type == 'tag' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.filenames.outputs.diktat-cli-zip }}
asset_name: ${{ steps.filenames.outputs.diktat-cli-zip }}
asset_content_type: application/zip
49 changes: 49 additions & 0 deletions .github/workflows/move-marketplace-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Move the Marketplace tag

on:
workflow_call:
inputs:
release-version:
required: true
type: string

jobs:
dist:
name: Move the Marketplace tag
# See https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
if: github.ref_type == 'tag'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- id: tag
name: Tag name
run: |
VERSION_MAJOR="$(echo '${{ inputs.release-version }}' | sed -nE '/^([0-9]+)\.[^\.]+.*$/s//\1/p')"
echo "name=v${VERSION_MAJOR}" >>"${GITHUB_OUTPUT}"
shell: bash

# The tag may not exist yet, so continue on error.
- name: Delete local tag
run: |
git tag -d '${{ steps.tag.outputs.name }}'
continue-on-error: true
shell: bash

# The tag may not exist yet, so continue on error.
- name: Delete remote tag
run: |
git push --delete origin '${{ steps.tag.outputs.name }}'
continue-on-error: true
shell: bash

- name: Create local tag
run: |
git tag '${{ steps.tag.outputs.name }}'
shell: bash

- name: Push local tag
run: |
git push origin '${{ steps.tag.outputs.name }}'
shell: bash
79 changes: 39 additions & 40 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: Create a new release

on:
workflow_dispatch:
pull_request:
push:
tags:
- 'v*.*'
# Ignore simple tags which are just "aliases" used by the Marketplace.
# Ignore simple tags which are just "aliases" used by the Marketplace.
- '!v1'
- '!v2'
- '!v3'
Expand All @@ -16,51 +18,48 @@ on:
- '!v9'

jobs:
build:
name: Release
version:
name: Calculate the release version
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- run: |
echo "RELEASE_VERSION=${GITHUB_REF#'refs/tags/v'}" >>"${GITHUB_ENV}"
shell: bash
# Infer the release version. Assumes that tags are named `vX.Y.Z`.
- id: version
run: |
if [[ "${GITHUB_REF_TYPE}" == 'branch' ]]
then
RELEASE_VERSION="${GITHUB_SHA}"
else
RELEASE_VERSION="${GITHUB_REF#'refs/tags/v'}"
RELEASE_VERSION="${RELEASE_VERSION//'/'/_}"
fi
- run: |
tar cf 'diktat-cli-${{ env.RELEASE_VERSION }}.tar' -C bin diktat
gzip -9 'diktat-cli-${{ env.RELEASE_VERSION }}.tar'
zip -jrX9 -Z bzip2 'diktat-cli-${{ env.RELEASE_VERSION }}.zip' bin
echo "release-version=${RELEASE_VERSION}" >>"${GITHUB_OUTPUT}"
shell: bash
outputs:
release-version: ${{ steps.version.outputs.release-version }}

- id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: v${{ env.RELEASE_VERSION }}
draft: false
prerelease: false
bindist-thin:
name: Binary distribution (thin)
needs: [ version ]
uses: ./.github/workflows/bindist-thin.yml
with:
release-version: ${{ needs.version.outputs.release-version }}
secrets: inherit

- name: Upload Release Asset (.tar.gz)
id: upload-release-asset-tar-gz
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: diktat-cli-${{ env.RELEASE_VERSION }}.tar.gz
asset_name: diktat-cli-${{ env.RELEASE_VERSION }}.tar.gz
asset_content_type: application/gzip
bindist-full:
name: Binary distribution (full)
needs: [ version, bindist-thin ]
uses: ./.github/workflows/bindist-full.yml
with:
release-version: ${{ needs.version.outputs.release-version }}
secrets: inherit

- name: Upload Release Asset (.zip)
id: upload-release-asset-zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: diktat-cli-${{ env.RELEASE_VERSION }}.zip
asset_name: diktat-cli-${{ env.RELEASE_VERSION }}.zip
asset_content_type: application/zip
move-tag:
name: Move the Marketplace tag
needs: [ version, bindist-thin, bindist-full ]
uses: ./.github/workflows/move-marketplace-tag.yml
with:
release-version: ${{ needs.version.outputs.release-version }}
secrets: inherit
15 changes: 14 additions & 1 deletion bin/diktat
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ function find_java() {
fi
}

# Similar to `realpath`, which is by default missing on Mac OS X.
function real_path() {
local file
file="$1"

echo "$(cd "$(dirname "${file}")"; pwd)/$(basename "${file}")"
}

# 1. Read the release descriptor
# 2. Filter the download URLs
# 3. Filter out any *.{asc,md5}
Expand All @@ -189,6 +197,11 @@ function download_from_github() {
mkdir -p "${LIB_DIR}"
mkdir -p "${LOG_DIR}"

# We'll be referencing `LOG_DIR` from within `LIB_DIR`.
# Make sure we use the absolute path.
local absolute_log_dir
absolute_log_dir="$(real_path "${LOG_DIR}")"

# Make sure the downloaded binaries are in the same directory as the script and
# do not pollute the directory of the project being checked.
cd "${LIB_DIR}"
Expand All @@ -211,7 +224,7 @@ function download_from_github() {
local release_url
release_url=$(printf "https://api.github.com/repos/%s/releases/%s\n" "${repository}" "${version}")
local download_log
download_log="${LOG_DIR}/$(echo "${repository}" | tr '/' '-')-download.log"
download_log="${absolute_log_dir}/$(echo "${repository}" | tr '/' '-')-download.log"

local progress
if (( DOWNLOAD_PROGRESS == 1 ))
Expand Down

0 comments on commit ec8e5f2

Please sign in to comment.