Skip to content

Commit 2ad4659

Browse files
committed
Add publishing GH actions pipeline
1 parent 312fb81 commit 2ad4659

12 files changed

Lines changed: 1172 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Get version
2+
description: Detects if build is a snapshot and gets the release or snapshot version
3+
4+
runs:
5+
using: composite
6+
steps:
7+
# Checking if this particular build is a snapshot build
8+
- name: Detect if snapshot
9+
id: get-is-snapshot
10+
shell: bash
11+
run: |
12+
# Check if tagged with release or release candidate
13+
TAG=$(git describe --exact-match --tags HEAD 2>/dev/null || echo "")
14+
echo "Detected Git tag: '$TAG'"
15+
16+
# Define regex patterns
17+
RE_PROD='^v?[0-9]+\.[0-9]+\.[0-9]+$'
18+
RE_RC='^v?[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+$'
19+
20+
if [[ "$TAG" =~ $RE_PROD ]]; then
21+
echo "Production release tag detected: $TAG"
22+
echo "is-snapshot=false" >> $GITHUB_OUTPUT
23+
exit 0
24+
elif [[ "$TAG" =~ $RE_RC ]]; then
25+
echo "Release candidate tag detected: $TAG"
26+
echo "is-snapshot=false" >> $GITHUB_OUTPUT
27+
exit 0
28+
else
29+
echo "No matching tag found"
30+
echo "is-snapshot=true" >> $GITHUB_OUTPUT
31+
fi
32+
33+
# Checking if previous commit contains pom.xml. This should always return true
34+
COMMIT_REF="HEAD~1"
35+
if ! git show "${COMMIT_REF}:pom.xml" &>/dev/null; then
36+
echo "Error: pom.xml not found in commit ${COMMIT_REF}"
37+
echo "is-snapshot='true'" >> $GITHUB_OUTPUT
38+
exit 0
39+
fi
40+
41+
# Getting previous version
42+
OLD_VERSIONS=$(git show "${COMMIT_REF}:pom.xml" | sed -n '0,/<version>/ s/.*<version>\([^<]*\)<\/version>.*/\1/p')
43+
44+
# Getting current version
45+
NEW_VERSIONS=$(sed -n '0,/<version>/ s/.*<version>\([^<]*\)<\/version>.*/\1/p' pom.xml)
46+
47+
echo "old versions: ${OLD_VERSIONS}, new versions: ${NEW_VERSIONS}"
48+
# Compare the extracted versions. CI will not commit snapshot version.
49+
if [[ "${OLD_VERSIONS}" != "${NEW_VERSIONS}" ]]; then
50+
echo "is-snapshot=false" >> $GITHUB_OUTPUT
51+
else
52+
echo "is-snapshot=true" >> $GITHUB_OUTPUT
53+
fi
54+
55+
- name: Get release or snapshot-version
56+
id: get-release-version
57+
shell: bash
58+
run: |
59+
IS_SNAPSHOT=${{ steps.get-is-snapshot.outputs.is-snapshot }}
60+
if [ $IS_SNAPSHOT == "true" ];then
61+
echo release-version="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)-SNAPSHOT_$GITHUB_SHA" >> $GITHUB_OUTPUT
62+
else
63+
echo release-version="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT
64+
fi
65+
66+
outputs:
67+
is-snapshot:
68+
description: Whether this is a snapshot build
69+
value: ${{ steps.get-is-snapshot.outputs.is-snapshot }}
70+
release-version:
71+
description: The release or snapshot version
72+
value: ${{ steps.get-release-version.outputs.release-version }}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Publish build-info to JFrog
2+
description: "Publishes build-info to JFrog"
3+
4+
inputs:
5+
jfrog-platform-url:
6+
description: "JFrog platform URL"
7+
required: false
8+
default: https://aerospike.jfrog.io
9+
oidc-provider:
10+
description: "OIDC provider name"
11+
required: true
12+
oidc-audience:
13+
description: "ODIC audience"
14+
required: true
15+
build-path:
16+
description: "Path to which build info is to be published"
17+
required: true
18+
variables:
19+
description: "Any additional variables to be published as part of build. The input here should be valid JSON in the form {'env_variable_key': 'env_variable_value'}, .e.g {'SONATYPE_STAGING_BUILD_ID': '070c07e25e937888ed9740ee825afa24bf184722'}"
20+
required: true
21+
22+
runs:
23+
using: "composite"
24+
steps:
25+
- name: Debug publish to github
26+
shell: bash
27+
run: |
28+
echo "${{ inputs.jfrog-platform-url }}"
29+
echo "${{ inputs.build-path }}"
30+
31+
- name: Set up JFrog credentials
32+
id: setup-jfrog-cli
33+
uses: step-security/setup-jfrog-cli@a6b41f8338bea0983ddff6bd4ede7d2dcd81e1fa # v4.8.1
34+
env:
35+
JF_URL: ${{ inputs.jfrog-platform-url }}
36+
JF_PROJECT: database
37+
with:
38+
version: 2.72.2
39+
oidc-provider-name: ${{ inputs.oidc-provider }}
40+
oidc-audience: ${{ inputs.oidc-audience }}
41+
42+
# Parsing out env variables and values and setting them in the environment
43+
- name: Set env variables provided with variables
44+
shell: bash
45+
run: |
46+
ENV_VARIABLES='${{ inputs.variables }}'
47+
echo "$ENV_VARIABLES" | jq -r 'to_entries | .[] | "\(.key)=\(.value)"' >> $GITHUB_ENV
48+
49+
# Pushing build info to JFrog
50+
- name: Upload artifacts
51+
shell: bash
52+
run: |
53+
BUILD_ID=$(echo "${{ inputs.build-path }}" | sed 's/.*_\(.*\)\/.*/\1/')
54+
BUILD_PATH="promote_${BUILD_ID}"
55+
56+
# record env variables
57+
jf rt bce ${BUILD_PATH} ${{ github.run_number }}
58+
59+
# record git info
60+
jf rt bag ${BUILD_PATH} ${{ github.run_number }}
61+
62+
# publish build info
63+
jf rt bp ${BUILD_PATH} ${{ github.run_number }}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Publish artifacts to github
2+
description: "Publish artifacts to github"
3+
4+
inputs:
5+
staging-folder:
6+
description: ""
7+
required: false
8+
default: staging
9+
target-folder:
10+
description: ""
11+
required: false
12+
default: github
13+
release-notes:
14+
description: "Release notes"
15+
required: true
16+
github-token:
17+
description: "Github auth token"
18+
required: true
19+
artifact-version:
20+
description: "Version of the artifact to release"
21+
required: true
22+
build-name-number:
23+
description: "String containing build name, number and jdk versions"
24+
required: true
25+
26+
runs:
27+
using: "composite"
28+
steps:
29+
- name: Debug publish to github
30+
shell: bash
31+
run: |
32+
echo "${{ inputs.staging-folder }}"
33+
echo "${{ inputs.target-folder }}"
34+
echo "${{ inputs.artifact-version }}"
35+
echo "${{ inputs.release-notes }}"
36+
echo "${{ inputs.build-name-number }}"
37+
38+
- id: get-artifact-version
39+
shell: bash
40+
run: |
41+
VERSION="${{ inputs.artifact-version }}"
42+
echo "artifact-version=${VERSION}" >> $GITHUB_OUTPUT
43+
44+
- name: Create upload archive for github
45+
id: create-artifact
46+
shell: bash
47+
run: |
48+
src="${{ inputs.staging-folder }}"
49+
dest="${{ inputs.target-folder }}"
50+
51+
find "$src" -type f \
52+
-exec cp {} "$dest" \;
53+
54+
# Listing staged artifacts to be uploaded
55+
- id: get-github-release-artifact-names
56+
working-directory: ${{ inputs.target-folder }}
57+
shell: bash
58+
run: |
59+
ARTIFACTS=$(ls | sed "s|^|${{ inputs.target-folder }}/|")
60+
61+
echo "release-artifacts<<EOF" >> $GITHUB_OUTPUT
62+
echo "${ARTIFACTS}" >> $GITHUB_OUTPUT
63+
echo "EOF" >> $GITHUB_OUTPUT
64+
65+
- name: Debug show content of the upload archive
66+
shell: bash
67+
run: |
68+
pwd
69+
ls ${{ inputs.target-folder }} | sed 's/^//'
70+
71+
- name: Debug GitHub publish input
72+
shell: bash
73+
working-directory: ${{ inputs.target-folder }}
74+
run: |
75+
echo "working directory: ${{ inputs.target-folder }}"
76+
echo "tag name: Release ${{ steps.get-artifact-version.outputs.artifact-version }}"
77+
echo "body: Changes for release ${{ steps.get-artifact-version.outputs.artifact-version }}"
78+
echo "body: ${{ inputs.release-notes }}"
79+
echo "files: ${{ steps.get-github-release-artifact-names.outputs.release-artifacts }}"
80+
81+
- name: Publish release to github
82+
uses: step-security/action-gh-release@5f6a6ab53a5a2c000ff3a16fad038291e5b97ce7 # v2.4.2
83+
with:
84+
token: ${{ inputs.github-token }}
85+
tag_name: ${{ steps.get-artifact-version.outputs.artifact-version }}
86+
body: |
87+
Changes for release ${{ steps.get-artifact-version.outputs.artifact-version }}
88+
${{ inputs.release-notes }}
89+
draft: true
90+
prerelease: false
91+
files: ${{ steps.get-github-release-artifact-names.outputs.release-artifacts }}

0 commit comments

Comments
 (0)