Skip to content

Commit

Permalink
Add Harbor CR upload action (#41)
Browse files Browse the repository at this point in the history
- Add Harbor CR upload action
- Rename upload-action as upload-action-jfrog
- Fix tag regular expression to support tags without endings

Signed-off-by: Ivan Kuznetsov <[email protected]>
  • Loading branch information
jsvapiav authored Apr 26, 2024
1 parent df20646 commit 7d97765
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 13 deletions.
37 changes: 37 additions & 0 deletions .github/actions/upload-action-harbor/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-FileCopyrightText: 2022-2024 TII (SSRC) and the Ghaf contributors
#
# SPDX-License-Identifier: Apache-2.0

name: Push artifacts to Harbor artifactory
description: Push artifacts to Harbor artifactory

inputs:
HARBOR_UNAME:
description: 'user account for artifactory'
required: true
HARBOR_TOKEN:
description: 'api-key for artifactory'
required: true
HARBOR_URL:
description: 'artifactory url'
required: true
input-paths:
description: 'input-paths'
required: true

runs:
using: "composite"
steps:
- name: Preparing artifactory for upload
uses: oras-project/setup-oras@v1
- run: oras version
shell: bash
- run: echo "${{ github.action_path }}" >> $GITHUB_PATH
shell: bash
- run: upload.sh
env:
HARBOR_UNAME: ${{ inputs.HARBOR_UNAME }}
HARBOR_TOKEN: ${{ inputs.HARBOR_TOKEN }}
HARBOR_URL: ${{ inputs.HARBOR_URL }}
INPUT_PATHS: ${{ inputs.input-paths }}
shell: bash
47 changes: 47 additions & 0 deletions .github/actions/upload-action-harbor/upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash -e
# SPDX-FileCopyrightText: 2022-2024 TII (SSRC) and the Ghaf contributors
#
# SPDX-License-Identifier: Apache-2.0

err_print() {
printf "%s" "$*" >&2
}

err_exit() {
local rc=$1
shift
err_print "$@"
exit "$rc"
}

echo "::group::Input validation"

[ ! "$HARBOR_URL" ] && err_exit 1 "HARBOR_URL undefined"
[ ! "$HARBOR_UNAME" ] && err_exit 1 "HARBOR_UNAME undefined"
[ ! "$HARBOR_TOKEN" ] && err_exit 1 "HARBOR_TOKEN undefined"

for input in $INPUT_PATHS; do
SOURCE_DIR=$(echo "$input" | cut -d ":" -f 1)
DEST_DIR=$(echo "$input" | cut -d ":" -f 2)
echo "SOURCE_DIR=$SOURCE_DIR"
echo "DEST_DIR=$DEST_DIR"
[ ! "$SOURCE_DIR" ] && err_exit 1 "SOURCE_DIR undefined"
[ ! "$DEST_DIR" ] && err_exit 1 "DEST_DIR undefined"
done

echo "::endgroup::"
echo "::group::Artifact upload"

echo $HARBOR_TOKEN | oras login $HARBOR_URL -u $HARBOR_UNAME --password-stdin

for input in $INPUT_PATHS; do
SOURCE_DIR=$(echo "$input" | cut -d ":" -f 1)
DEST_DIR=$(echo "$input" | cut -d ":" -f 2)
TAG=$(echo "$input" | cut -d ":" -f 3)

UPLOAD_DIR=$SOURCE_DIR
echo "oras push "$HARBOR_URL/$DEST_DIR:$TAG" $UPLOAD_DIR"
oras push --disable-path-validation "$HARBOR_URL/$DEST_DIR:$TAG" $UPLOAD_DIR
done

echo "::endgroup::"
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ inputs:
JFROG_URL:
description: 'artifactory url'
required: true
build-num:
description: 'build number'
required: false
input-paths:
description: 'input-paths'
required: true
Expand All @@ -34,6 +31,5 @@ runs:
JFROG_UNAME: ${{ inputs.JFROG_UNAME }}
JFROG_TOKEN: ${{ inputs.JFROG_TOKEN }}
JFROG_URL: ${{ inputs.JFROG_URL }}
BUILD_NUM: ${{ inputs.build-num }}
INPUT_PATHS: ${{ inputs.input-paths }}
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ for input in $INPUT_PATHS; do
DEST_DIR=$(echo "$input" | cut -d ":" -f 2)

UPLOAD_DIR=$SOURCE_DIR
if [ "$BUILD_NUM" ]; then
UPLOAD_DIR=$SOURCE_DIR-b$BUILD_NUM
mv "$SOURCE_DIR" "$UPLOAD_DIR"
fi
echo "Run: jf rt u "$UPLOAD_DIR" "$DEST_DIR" --flat=true"
jf rt u "$UPLOAD_DIR" "$DEST_DIR" --flat=true
done
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: build
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9][a-z]*'
- 'v[0-9]+.[0-9]+.[0-9]*'

permissions:
contents: read
Expand Down Expand Up @@ -49,14 +49,20 @@ jobs:
build_target: 'fmo-os-installer-debug'
CACHIX_TOKEN: ${{ secrets.CACHIX_TOKEN }}
RA_TOKEN: ${{ secrets.RA_TOKEN }}
- name: Prepare artifactory for upload
uses: "jfrog/setup-jfrog-cli@v2"
- name: Push to artifactory
uses: ./.github/actions/upload-action
- name: Push to JFrog artifactory
uses: ./.github/actions/upload-action-jfrog
with:
JFROG_UNAME: ${{ secrets.JFROG_UNAME }}
JFROG_TOKEN: ${{ secrets.JFROG_TOKEN }}
JFROG_URL: ${{ secrets.JFROG_URL }}
input-paths: |
${{ github.workspace }}/${{ steps.build.outputs.outimg }}:tii-fmo-os/releases/FMO-OS_inst_${{ steps.tag.outputs.TAG_VERSION }}.iso
- name: Push to Harbor artifactory
uses: ./.github/actions/upload-action-harbor
with:
HARBOR_UNAME: ${{ secrets.HARBOR_UNAME }}
HARBOR_TOKEN: ${{ secrets.HARBOR_TOKEN }}
HARBOR_URL: ${{ secrets.HARBOR_URL }}
input-paths: |
${{ github.workspace }}/${{ steps.build.outputs.outimg }}:fmo/pmc-installer:${{ steps.tag.outputs.TAG_VERSION }}

0 comments on commit 7d97765

Please sign in to comment.