Skip to content

Commit ec8e5f2

Browse files
Enable creation of full, offline binary releases (w/dependencies) (#16)
1 parent 18bfc2e commit ec8e5f2

File tree

5 files changed

+286
-41
lines changed

5 files changed

+286
-41
lines changed

.github/workflows/bindist-full.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Create a binary distribution (full)
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
release-version:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
dist:
12+
name: Binary distribution (full)
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- id: filenames
19+
name: Archive names
20+
run: |
21+
echo "diktat-cli-tar=diktat-cli-${{ inputs.release-version }}-full.tar" >>"${GITHUB_OUTPUT}"
22+
echo "diktat-cli-tgz=diktat-cli-${{ inputs.release-version }}-full.tar.gz" >>"${GITHUB_OUTPUT}"
23+
echo "diktat-cli-zip=diktat-cli-${{ inputs.release-version }}-full.zip" >>"${GITHUB_OUTPUT}"
24+
shell: bash
25+
26+
- uses: actions/setup-java@v3
27+
with:
28+
distribution: zulu
29+
java-version: 17
30+
31+
- name: Download dependencies
32+
run: |
33+
bin/diktat --no-download-progress -V
34+
env:
35+
GITHUB_TOKEN: ${{ github.token }}
36+
shell: bash
37+
38+
- name: Archive
39+
run: |
40+
tar cf '${{ steps.filenames.outputs.diktat-cli-tar }}' --exclude-backups --exclude-vcs --exclude-vcs-ignore --exclude='*.bat' --exclude='*.cmd' -C bin .
41+
gzip -9 '${{ steps.filenames.outputs.diktat-cli-tar }}'
42+
zip -jrX9 -Z bzip2 '${{ steps.filenames.outputs.diktat-cli-zip }}' bin
43+
shell: bash
44+
45+
# Upload a .tar.gz artifact, except when this is a release.
46+
- name: Upload ${{ steps.filenames.outputs.diktat-cli-tgz }}
47+
if: ${{ github.ref_type == 'branch' }}
48+
uses: actions/upload-artifact@v3
49+
with:
50+
name: ${{ steps.filenames.outputs.diktat-cli-tgz }}
51+
path: ${{ steps.filenames.outputs.diktat-cli-tgz }}
52+
if-no-files-found: error
53+
retention-days: 1
54+
55+
# Upload a .zip artifact, except when this is a release.
56+
- name: Upload ${{ steps.filenames.outputs.diktat-cli-zip }}
57+
if: ${{ github.ref_type == 'branch' }}
58+
uses: actions/upload-artifact@v3
59+
with:
60+
name: ${{ steps.filenames.outputs.diktat-cli-zip }}
61+
path: ${{ steps.filenames.outputs.diktat-cli-zip }}
62+
if-no-files-found: error
63+
retention-days: 1
64+
65+
- id: create_release
66+
if: ${{ github.ref_type == 'tag' }}
67+
uses: actions/create-release@v1
68+
env:
69+
GITHUB_TOKEN: ${{ github.token }}
70+
with:
71+
tag_name: ${{ github.ref }}
72+
release_name: v${{ inputs.release-version }}
73+
draft: false
74+
prerelease: false
75+
76+
- name: Upload release asset (${{ steps.filenames.outputs.diktat-cli-tgz }})
77+
id: upload-release-asset-tgz
78+
if: ${{ github.ref_type == 'tag' }}
79+
uses: actions/upload-release-asset@v1
80+
env:
81+
GITHUB_TOKEN: ${{ github.token }}
82+
with:
83+
upload_url: ${{ steps.create_release.outputs.upload_url }}
84+
asset_path: ${{ steps.filenames.outputs.diktat-cli-tgz }}
85+
asset_name: ${{ steps.filenames.outputs.diktat-cli-tgz }}
86+
asset_content_type: application/gzip
87+
88+
- name: Upload release asset (${{ steps.filenames.outputs.diktat-cli-zip }})
89+
id: upload-release-asset-zip
90+
if: ${{ github.ref_type == 'tag' }}
91+
uses: actions/upload-release-asset@v1
92+
env:
93+
GITHUB_TOKEN: ${{ github.token }}
94+
with:
95+
upload_url: ${{ steps.create_release.outputs.upload_url }}
96+
asset_path: ${{ steps.filenames.outputs.diktat-cli-zip }}
97+
asset_name: ${{ steps.filenames.outputs.diktat-cli-zip }}
98+
asset_content_type: application/zip

.github/workflows/bindist-thin.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Create a binary distribution (thin)
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
release-version:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
dist:
12+
name: Binary distribution (thin)
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- id: filenames
19+
name: Archive names
20+
run: |
21+
echo "diktat-cli-tar=diktat-cli-${{ inputs.release-version }}.tar" >>"${GITHUB_OUTPUT}"
22+
echo "diktat-cli-tgz=diktat-cli-${{ inputs.release-version }}.tar.gz" >>"${GITHUB_OUTPUT}"
23+
echo "diktat-cli-zip=diktat-cli-${{ inputs.release-version }}.zip" >>"${GITHUB_OUTPUT}"
24+
shell: bash
25+
26+
- name: Archive
27+
run: |
28+
tar cf '${{ steps.filenames.outputs.diktat-cli-tar }}' --exclude-backups --exclude-vcs --exclude-vcs-ignore --exclude='*.bat' --exclude='*.cmd' -C bin diktat
29+
gzip -9 '${{ steps.filenames.outputs.diktat-cli-tar }}'
30+
zip -jrX9 -Z bzip2 '${{ steps.filenames.outputs.diktat-cli-zip }}' bin
31+
shell: bash
32+
33+
# Upload a .tar.gz artifact, except when this is a release.
34+
- name: Upload ${{ steps.filenames.outputs.diktat-cli-tgz }}
35+
if: ${{ github.ref_type == 'branch' }}
36+
uses: actions/upload-artifact@v3
37+
with:
38+
name: ${{ steps.filenames.outputs.diktat-cli-tgz }}
39+
path: ${{ steps.filenames.outputs.diktat-cli-tgz }}
40+
if-no-files-found: error
41+
retention-days: 1
42+
43+
# Upload a .zip artifact, except when this is a release.
44+
- name: Upload ${{ steps.filenames.outputs.diktat-cli-zip }}
45+
if: ${{ github.ref_type == 'branch' }}
46+
uses: actions/upload-artifact@v3
47+
with:
48+
name: ${{ steps.filenames.outputs.diktat-cli-zip }}
49+
path: ${{ steps.filenames.outputs.diktat-cli-zip }}
50+
if-no-files-found: error
51+
retention-days: 1
52+
53+
- id: create_release
54+
if: ${{ github.ref_type == 'tag' }}
55+
uses: actions/create-release@v1
56+
env:
57+
GITHUB_TOKEN: ${{ github.token }}
58+
with:
59+
tag_name: ${{ github.ref }}
60+
release_name: v${{ inputs.release-version }}
61+
draft: false
62+
prerelease: false
63+
64+
- name: Upload release asset (${{ steps.filenames.outputs.diktat-cli-tgz }})
65+
id: upload-release-asset-tgz
66+
if: ${{ github.ref_type == 'tag' }}
67+
uses: actions/upload-release-asset@v1
68+
env:
69+
GITHUB_TOKEN: ${{ github.token }}
70+
with:
71+
upload_url: ${{ steps.create_release.outputs.upload_url }}
72+
asset_path: ${{ steps.filenames.outputs.diktat-cli-tgz }}
73+
asset_name: ${{ steps.filenames.outputs.diktat-cli-tgz }}
74+
asset_content_type: application/gzip
75+
76+
- name: Upload release asset (${{ steps.filenames.outputs.diktat-cli-zip }})
77+
id: upload-release-asset-zip
78+
if: ${{ github.ref_type == 'tag' }}
79+
uses: actions/upload-release-asset@v1
80+
env:
81+
GITHUB_TOKEN: ${{ github.token }}
82+
with:
83+
upload_url: ${{ steps.create_release.outputs.upload_url }}
84+
asset_path: ${{ steps.filenames.outputs.diktat-cli-zip }}
85+
asset_name: ${{ steps.filenames.outputs.diktat-cli-zip }}
86+
asset_content_type: application/zip
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Move the Marketplace tag
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
release-version:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
dist:
12+
name: Move the Marketplace tag
13+
# See https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
14+
if: github.ref_type == 'tag'
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- id: tag
21+
name: Tag name
22+
run: |
23+
VERSION_MAJOR="$(echo '${{ inputs.release-version }}' | sed -nE '/^([0-9]+)\.[^\.]+.*$/s//\1/p')"
24+
echo "name=v${VERSION_MAJOR}" >>"${GITHUB_OUTPUT}"
25+
shell: bash
26+
27+
# The tag may not exist yet, so continue on error.
28+
- name: Delete local tag
29+
run: |
30+
git tag -d '${{ steps.tag.outputs.name }}'
31+
continue-on-error: true
32+
shell: bash
33+
34+
# The tag may not exist yet, so continue on error.
35+
- name: Delete remote tag
36+
run: |
37+
git push --delete origin '${{ steps.tag.outputs.name }}'
38+
continue-on-error: true
39+
shell: bash
40+
41+
- name: Create local tag
42+
run: |
43+
git tag '${{ steps.tag.outputs.name }}'
44+
shell: bash
45+
46+
- name: Push local tag
47+
run: |
48+
git push origin '${{ steps.tag.outputs.name }}'
49+
shell: bash

.github/workflows/release.yml

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
name: Create a new release
22

33
on:
4+
workflow_dispatch:
5+
pull_request:
46
push:
57
tags:
68
- 'v*.*'
7-
# Ignore simple tags which are just "aliases" used by the Marketplace.
9+
# Ignore simple tags which are just "aliases" used by the Marketplace.
810
- '!v1'
911
- '!v2'
1012
- '!v3'
@@ -16,51 +18,48 @@ on:
1618
- '!v9'
1719

1820
jobs:
19-
build:
20-
name: Release
21+
version:
22+
name: Calculate the release version
2123
runs-on: ubuntu-latest
22-
2324
steps:
2425
- uses: actions/checkout@v3
2526

26-
- run: |
27-
echo "RELEASE_VERSION=${GITHUB_REF#'refs/tags/v'}" >>"${GITHUB_ENV}"
28-
shell: bash
27+
# Infer the release version. Assumes that tags are named `vX.Y.Z`.
28+
- id: version
29+
run: |
30+
if [[ "${GITHUB_REF_TYPE}" == 'branch' ]]
31+
then
32+
RELEASE_VERSION="${GITHUB_SHA}"
33+
else
34+
RELEASE_VERSION="${GITHUB_REF#'refs/tags/v'}"
35+
RELEASE_VERSION="${RELEASE_VERSION//'/'/_}"
36+
fi
2937
30-
- run: |
31-
tar cf 'diktat-cli-${{ env.RELEASE_VERSION }}.tar' -C bin diktat
32-
gzip -9 'diktat-cli-${{ env.RELEASE_VERSION }}.tar'
33-
zip -jrX9 -Z bzip2 'diktat-cli-${{ env.RELEASE_VERSION }}.zip' bin
38+
echo "release-version=${RELEASE_VERSION}" >>"${GITHUB_OUTPUT}"
3439
shell: bash
40+
outputs:
41+
release-version: ${{ steps.version.outputs.release-version }}
3542

36-
- id: create_release
37-
uses: actions/create-release@v1
38-
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40-
with:
41-
tag_name: ${{ github.ref }}
42-
release_name: v${{ env.RELEASE_VERSION }}
43-
draft: false
44-
prerelease: false
43+
bindist-thin:
44+
name: Binary distribution (thin)
45+
needs: [ version ]
46+
uses: ./.github/workflows/bindist-thin.yml
47+
with:
48+
release-version: ${{ needs.version.outputs.release-version }}
49+
secrets: inherit
4550

46-
- name: Upload Release Asset (.tar.gz)
47-
id: upload-release-asset-tar-gz
48-
uses: actions/upload-release-asset@v1
49-
env:
50-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51-
with:
52-
upload_url: ${{ steps.create_release.outputs.upload_url }}
53-
asset_path: diktat-cli-${{ env.RELEASE_VERSION }}.tar.gz
54-
asset_name: diktat-cli-${{ env.RELEASE_VERSION }}.tar.gz
55-
asset_content_type: application/gzip
51+
bindist-full:
52+
name: Binary distribution (full)
53+
needs: [ version, bindist-thin ]
54+
uses: ./.github/workflows/bindist-full.yml
55+
with:
56+
release-version: ${{ needs.version.outputs.release-version }}
57+
secrets: inherit
5658

57-
- name: Upload Release Asset (.zip)
58-
id: upload-release-asset-zip
59-
uses: actions/upload-release-asset@v1
60-
env:
61-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62-
with:
63-
upload_url: ${{ steps.create_release.outputs.upload_url }}
64-
asset_path: diktat-cli-${{ env.RELEASE_VERSION }}.zip
65-
asset_name: diktat-cli-${{ env.RELEASE_VERSION }}.zip
66-
asset_content_type: application/zip
59+
move-tag:
60+
name: Move the Marketplace tag
61+
needs: [ version, bindist-thin, bindist-full ]
62+
uses: ./.github/workflows/move-marketplace-tag.yml
63+
with:
64+
release-version: ${{ needs.version.outputs.release-version }}
65+
secrets: inherit

bin/diktat

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ function find_java() {
172172
fi
173173
}
174174

175+
# Similar to `realpath`, which is by default missing on Mac OS X.
176+
function real_path() {
177+
local file
178+
file="$1"
179+
180+
echo "$(cd "$(dirname "${file}")"; pwd)/$(basename "${file}")"
181+
}
182+
175183
# 1. Read the release descriptor
176184
# 2. Filter the download URLs
177185
# 3. Filter out any *.{asc,md5}
@@ -189,6 +197,11 @@ function download_from_github() {
189197
mkdir -p "${LIB_DIR}"
190198
mkdir -p "${LOG_DIR}"
191199

200+
# We'll be referencing `LOG_DIR` from within `LIB_DIR`.
201+
# Make sure we use the absolute path.
202+
local absolute_log_dir
203+
absolute_log_dir="$(real_path "${LOG_DIR}")"
204+
192205
# Make sure the downloaded binaries are in the same directory as the script and
193206
# do not pollute the directory of the project being checked.
194207
cd "${LIB_DIR}"
@@ -211,7 +224,7 @@ function download_from_github() {
211224
local release_url
212225
release_url=$(printf "https://api.github.com/repos/%s/releases/%s\n" "${repository}" "${version}")
213226
local download_log
214-
download_log="${LOG_DIR}/$(echo "${repository}" | tr '/' '-')-download.log"
227+
download_log="${absolute_log_dir}/$(echo "${repository}" | tr '/' '-')-download.log"
215228

216229
local progress
217230
if (( DOWNLOAD_PROGRESS == 1 ))

0 commit comments

Comments
 (0)