diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000000..bd69f2fc13 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,105 @@ +name: Build +on: + push: + branches: + # - master + # - 'release-*' + - richard-dev + tags: + # - 'v*' + - 'richard-dev-v*' +env: + BUILD_DEBUG: + CI_BRANCH: + CI_BUILD_TAG: +jobs: + set-envs: + runs-on: ubuntu-latest + steps: + - if: ${{ github.event.action == 'branches' }} + name: Set Branch Env + run: echo "CI_BRANCH=$(github.ref_name)" >> $GITHUB_ENV + - if: ${{ github.event.action == 'tags' }} + name: Set Tag Env + run: echo "CI_BUILD_TAG=$(github.ref_name)" >> $GITHUB_ENV + test: + uses: ./.github/workflows/test.yaml + build: + runs-on: ubuntu-latest + needs: [set-envs, test] + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 1 + + - name: Run Setup + uses: ./.github/actions/setup + + - id: build + name: Build + # -l -v latest2 + run: ./scripts/build-static + + - name: Archive build + uses: actions/upload-artifact@v4 + with: + name: BUILD_DIR + path: ${{ steps.build.outputs.BUILD_DIR }} + retention-days: 1 + + - name: Archive build + uses: actions/upload-artifact@v4 + with: + name: BUILD_TGZ + path: ${{ steps.build.outputs.BUILD_TGZ }} + retention-days: 1 + # upload: + # runs-on: ubuntu-latest + # needs: build + # permissions: + # contents: 'read' + # id-token: 'write' + # env: + # GS_BUCKET_NAME: + # steps: + # - name: Download build directory + # uses: actions/download-artifact@v4 + # with: + # name: BUILD_DIR + # path: build_dir + # - name: Download build tar + # uses: actions/download-artifact@v4 + # with: + # name: BUILD_TGZ + # path: build_tgz + # # https://github.com/google-github-actions/auth + # - name: auth + # uses: 'google-github-actions/auth@v2' + # with: + # credentials_json: '' + # # workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' + # # service_account: 'my-service-account@my-project.iam.gserviceaccount.com' + # # https://github.com/google-github-actions/upload-cloud-storage + # - name: upload build + # uses: 'google-github-actions/upload-cloud-storage@v2' + # with: + # path: build_dir + # # https://releases.rancher.com/ui/2.8.0/... + # destination: releases.rancher.com/ui/${{ env.VERSION }} + # parent: false + # headers: |- + # cache-control: no-cache,must-revalidate + # - name: upload tar + # uses: 'google-github-actions/upload-cloud-storage@v2' + # with: + # path: build_tgz + # # https://releases.rancher.com/ui/2.8.0.tar.gz + # destination: releases.rancher.com/ui + # parent: false + +#project_id +# GS_PROJECT_NAME 'Rancher' +# VERSION +# CDN="releases.rancher.com/ui" +# GS_URL="${GS_URL:-gs://${CDN}}" +# https://releases.rancher.com/ui/latest2/index.html diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6a5e443c7c..03b1e6167e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -5,9 +5,17 @@ on: - master - 'release-*' pull_request: - branches: - - master - - 'release-*' + branches: + - master + - 'release-*' + workflow_call: + # inputs: + # config-path: + # required: true + # type: string + # secrets: + # envPAT: + # required: true jobs: unit-test: diff --git a/package.json b/package.json index dcb920e4b1..fffc9616bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ui", - "version": "master-dev", + "version": "richard-dev", "private": true, "repository": "https://github.com/rancher/ui", "license": "Apache-2.0", @@ -141,4 +141,4 @@ "lib/shared" ] } -} +} \ No newline at end of file diff --git a/scripts/build-static b/scripts/build-static index 7268a6cc64..206ce3b6d1 100755 --- a/scripts/build-static +++ b/scripts/build-static @@ -8,10 +8,10 @@ if [[ -n "${BUILD_DEBUG}" ]]; then fi # Initialize empty variables -: ${CI_BRANCH=""} -: ${UPLOAD_LATEST=""} +# : ${CI_BRANCH=""} +# : ${UPLOAD_LATEST=""} # Drone will set this on tag -: ${CI_BUILD_TAG="${DRONE_TAG:-}"} +# : ${CI_BUILD_TAG=""} # cd to app root CWD=$(dirname $0) @@ -25,18 +25,18 @@ source ./scripts/utils.sh # ------------------------------------- +# -u - Upload to GCE +# -s - Skip tests +# -l - Build as "latest2" instead of the version in package.json +# -p=PROJECT_NAME - name of the Google Cloud project hosting the storage bucket +# -t - Tag and push tag function printHelp() { cat 1>&2 < -v=VERSION - Force version to be VERSION instead of what is in package.json - -p=PROJECT_NAME - name of the Google Cloud project hosting the storage bucket EOF exit 1; } @@ -62,13 +62,13 @@ fi FORCE=0 LATEST=0 MODE="" -UPLOAD=0 -TAG=0 -TEST=1 +# UPLOAD=0 +# TAG=0 +# TEST=1 ENVIRONMENT="production" FINGERPRINT="yes" : ${FORCE_VERSION:=""} -GS_PROJECT_NAME="${GS_PROJECT_NAME:-Rancher}" +# GS_PROJECT_NAME="${GS_PROJECT_NAME:-Rancher}" while getopts ":dlustfv:c:p:m:" opt;do case $opt in @@ -78,30 +78,30 @@ while getopts ":dlustfv:c:p:m:" opt;do f) FORCE=1 ;; - l) - LATEST=1 - ;; + # l) + # LATEST=1 + # ;; m) MODE=$OPTARG ;; - s) - TEST=0 - ;; - t) - TAG=1 - ;; - u) - UPLOAD=1 - ;; + # s) + # TEST=0 + # ;; + # t) + # TAG=1 + # ;; + # u) + # UPLOAD=1 + # ;; v) FORCE_VERSION=$OPTARG ;; c) CDN=$OPTARG ;; - p) - GS_PROJECT_NAME=$OPTARG - ;; + # p) + # GS_PROJECT_NAME=$OPTARG + # ;; \?) echo "Invalid arguemnt: ${OPTARG}" printHelp @@ -125,33 +125,35 @@ if [[ `git status --porcelain` ]]; then fi # UPLOAD_LATEST=true is set by Drone for auto upload to CDN -if [[ "${BRANCH}" == "master" ]] && [[ "${UPLOAD_LATEST}" == "true" ]]; then - UPLOAD=2 +# && [[ "${UPLOAD_LATEST}" == "true" ]] +if [[ "${BRANCH}" == "master" ]]; then + # UPLOAD=2 LATEST=1 fi -# Sanity checking -if [[ $LATEST -eq 1 ]] && [[ $TAG -eq 1 ]]; then - echo "You can't tag latest." - if [[ $FORCE -ne 1 ]]; then - exit 1; - fi -fi - -if ( [[ $TAG -eq 1 ]] || [[ $UPLOAD -ne 0 ]] ) && [[ "${BRANCH}" != "master" ]]; then - echo "You can only tag or upload the master branch (you are on '${BRANCH}')." - if [[ $FORCE -ne 1 ]]; then - exit 1; - fi -fi - -REMOTE=$(git config --get remote.origin.url) -if [[ $TAG -eq 1 ]] && [[ ! "${REMOTE}" =~ .*rancher/ui.* ]]; then - echo "You can only tag when origin is the main rancher/ui repo (you are on '${REMOTE}')." - if [[ $FORCE -ne 1 ]]; then - exit 1; - fi -fi +# # Sanity checking +# if [[ $LATEST -eq 1 ]] && [[ $TAG -eq 1 ]]; then +# echo "You can't tag latest." +# if [[ $FORCE -ne 1 ]]; then +# exit 1; +# fi +# fi + +# || [[ $UPLOAD -ne 0 ]] +# if ( [[ $TAG -eq 1 ]] ) && [[ "${BRANCH}" != "master" ]]; then +# echo "You can only tag or upload the master branch (you are on '${BRANCH}')." +# if [[ $FORCE -ne 1 ]]; then +# exit 1; +# fi +# fi + +# REMOTE=$(git config --get remote.origin.url) +# if [[ $TAG -eq 1 ]] && [[ ! "${REMOTE}" =~ .*rancher/ui.* ]]; then +# echo "You can only tag when origin is the main rancher/ui repo (you are on '${REMOTE}')." +# if [[ $FORCE -ne 1 ]]; then +# exit 1; +# fi +# fi if [[ "${FORCE_VERSION}" != "" ]]; then VERSION=${FORCE_VERSION} @@ -167,20 +169,24 @@ if [[ $LATEST -eq 1 ]]; then FINGERPRINT="no" fi -EXISTING=$(git tag -l "v${VERSION}") -if [[ $TAG -eq 1 ]] && [[ "${EXISTING}" = "v${VERSION}" ]]; then - echo "There is already an existing tag v${VERSION}" - if [[ $FORCE -ne 1 ]]; then - exit 1; - fi -fi +# EXISTING=$(git tag -l "v${VERSION}") +# if [[ $TAG -eq 1 ]] && [[ "${EXISTING}" = "v${VERSION}" ]]; then +# echo "There is already an existing tag v${VERSION}" +# if [[ $FORCE -ne 1 ]]; then +# exit 1; +# fi +# fi BUILD_PAR="dist/static" BUILD_DIR="${BUILD_PAR}/${VERSION}" BUILD_TGZ="${BUILD_PAR}/${VERSION}.tar.gz" -GS_URL="${GS_URL:-gs://${CDN}}" -GCLOUD_UUID="google/cloud-sdk@sha256:506775439bd4f44d90a3f6784f2b625e55c43635f9f2c4cae24ac4b3dea0277a" +echo "BUILD_DIR=${BUILD_DIR}" >> "$GITHUB_OUTPUT" +echo "BUILD_TGZ=${BUILD_TGZ}" >> "$GITHUB_OUTPUT" +echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT" +# GS_URL="${GS_URL:-gs://${CDN}}" + +# GCLOUD_UUID="google/cloud-sdk@sha256:506775439bd4f44d90a3f6784f2b625e55c43635f9f2c4cae24ac4b3dea0277a" echo "Branch: ${BRANCH}" if [[ "${VERSION}" != "${PKG_VERSION}" ]]; then @@ -188,16 +194,19 @@ if [[ "${VERSION}" != "${PKG_VERSION}" ]]; then fi echo "Version: ${VERSION}" echo "Build Dir: ${BUILD_DIR}" -echo "Options: Force=${FORCE}, Mode=${MODE}, Latest=${LATEST}, Test=${TEST}, Upload=${UPLOAD}, Tag=${TAG}" +# Upload=${UPLOAD}, +# Test=${TEST}, +# , Tag=${TAG}" +echo "Options: Force=${FORCE}, Mode=${MODE}, Latest=${LATEST}" echo "Current Directory: $(pwd)" -if [[ $TEST -eq 1 ]]; then - echo "Testing..." - runCmd ./node_modules/.bin/ember test - echo "Done Testing." -else - echo "Skipping Tests" -fi +# if [[ $TEST -eq 1 ]]; then +# echo "Testing..." +# runCmd ./node_modules/.bin/ember test +# echo "Done Testing." +# else +# echo "Skipping Tests" +# fi if [[ $LATEST -ne 1 ]]; then echo "Building Static Tarball..." @@ -219,40 +228,40 @@ UI_MODE="${MODE}" FINGERPRINT="${FINGERPRINT}" RANCHER="" CATALOG="" BASE_ASSETS # Create a file containing the version echo "${PKG_VERSION}" > ${BUILD_DIR}/VERSION.txt -if [[ $TAG -eq 1 ]]; then - runCmd git tag v${VERSION} - runCmd git push --tags -fi - -# Upload asset, either from laptop or from CI pipeline -if [[ -n "$UPLOAD" ]]; then - echo "Uploading..." - - ABS_BUILD_DIR="$(pwd)/${BUILD_DIR}" - GS_UPLOAD_COMMAND="gcs_upload_asset project_name=${GS_PROJECT_NAME} version=${VERSION} upload_target=${GS_URL}" - - if [[ $LATEST -ne 1 ]]; then - GS_UPLOAD_COMMAND+=" tgz_file=${BUILD_TGZ}" - else - GS_UPLOAD_COMMAND+=" is_latest=true" - fi - - if [[ $UPLOAD -eq 1 ]]; then - runCmd "${GS_UPLOAD_COMMAND} upload_source=${BUILD_DIR} disable_svcacct_auth=true" - fi - - if [[ $UPLOAD -eq 2 ]]; then - GS_SERVICE_ACCOUNT_KEYFILE="$(TMPDIR=$(pwd) && mktemp -t gs_service_account_keyfile.XXXXXXX)" - echo "${GS_SERVICE_ACCOUNT_KEY}" > "${GS_SERVICE_ACCOUNT_KEYFILE}" - - GS_UPLOAD_COMMAND+=" service_account_id=${GS_SERVICE_ACCOUNT_ID}" - runCmd "docker run --rm --name gcloud-config \ - -v ${GS_SERVICE_ACCOUNT_KEYFILE}:/tmp/keyfile.json \ - -v $(pwd)/scripts:/opt/rancher/scripts \ - -v ${ABS_BUILD_DIR}:/upload \ - ${GCLOUD_UUID} \ - /opt/rancher/scripts/${GS_UPLOAD_COMMAND}" - - rm "${GS_SERVICE_ACCOUNT_KEYFILE}" - fi -fi +# if [[ $TAG -eq 1 ]]; then +# runCmd git tag v${VERSION} +# runCmd git push --tags +# fi + +# # Upload asset, either from laptop or from CI pipeline +# if [[ -n "$UPLOAD" ]]; then +# echo "Uploading..." + +# ABS_BUILD_DIR="$(pwd)/${BUILD_DIR}" +# GS_UPLOAD_COMMAND="gcs_upload_asset project_name=${GS_PROJECT_NAME} version=${VERSION} upload_target=${GS_URL}" + +# if [[ $LATEST -ne 1 ]]; then +# GS_UPLOAD_COMMAND+=" tgz_file=${BUILD_TGZ}" +# else +# GS_UPLOAD_COMMAND+=" is_latest=true" +# fi + +# if [[ $UPLOAD -eq 1 ]]; then +# runCmd "${GS_UPLOAD_COMMAND} upload_source=${BUILD_DIR} disable_svcacct_auth=true" +# fi + +# if [[ $UPLOAD -eq 2 ]]; then +# GS_SERVICE_ACCOUNT_KEYFILE="$(TMPDIR=$(pwd) && mktemp -t gs_service_account_keyfile.XXXXXXX)" +# echo "${GS_SERVICE_ACCOUNT_KEY}" > "${GS_SERVICE_ACCOUNT_KEYFILE}" + +# GS_UPLOAD_COMMAND+=" service_account_id=${GS_SERVICE_ACCOUNT_ID}" +# runCmd "docker run --rm --name gcloud-config \ +# -v ${GS_SERVICE_ACCOUNT_KEYFILE}:/tmp/keyfile.json \ +# -v $(pwd)/scripts:/opt/rancher/scripts \ +# -v ${ABS_BUILD_DIR}:/upload \ +# ${GCLOUD_UUID} \ +# /opt/rancher/scripts/${GS_UPLOAD_COMMAND}" + +# rm "${GS_SERVICE_ACCOUNT_KEYFILE}" +# fi +# fi diff --git a/scripts/gcs_upload_asset b/scripts/gcs_upload_asset index d0c46c0249..2f2b3a1d88 100755 --- a/scripts/gcs_upload_asset +++ b/scripts/gcs_upload_asset @@ -1,7 +1,9 @@ -#!/bin/bash -x +# #!/bin/bash -x -set -eu +# set -eu -source "$(dirname $0)/utils.sh" +# source "$(dirname $0)/utils.sh" -gcs_upload_asset $@ +# gcs_upload_asset $@ + +exit 1 diff --git a/scripts/utils.sh b/scripts/utils.sh index 81d16b9513..1ce0e33d35 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -7,67 +7,67 @@ function runCmd() { fi } -# Upload specified asset to Google Cloud Storage -# required parameters: -# service_account_id - ID/name for service account -# project_name - the Google Cloud project name which owns the Storage bucket -# version - the upload version -# -# optional parameters: -# latest - we are uploading 'latest' which requires a some special upload magic -# upload_source - the directory or file to upload. Defaults to /upload. -# upload_target - the target gs:// URI for upload. Defaults to gs:///. -# service_account_keyfile - key file for service account in JSON format. Defaults to /tmp/keyfile.json. -# is_latest - flag that this is the latest version which changes the upload logic a bit. Defaults to 'false'. -# disable_svcacct_auth: disable automagic Service Account auto-authentication when. Primarily used for non-CI runs. Default 'false'. -# tgz_file: if upload is not latest, specify the relative path to tarball to upload. -function gcs_upload_asset() { - local $* +# # Upload specified asset to Google Cloud Storage +# # required parameters: +# # service_account_id - ID/name for service account +# # project_name - the Google Cloud project name which owns the Storage bucket +# # version - the upload version +# # +# # optional parameters: +# # latest - we are uploading 'latest' which requires a some special upload magic +# # upload_source - the directory or file to upload. Defaults to /upload. +# # upload_target - the target gs:// URI for upload. Defaults to gs:///. +# # service_account_keyfile - key file for service account in JSON format. Defaults to /tmp/keyfile.json. +# # is_latest - flag that this is the latest version which changes the upload logic a bit. Defaults to 'false'. +# # disable_svcacct_auth: disable automagic Service Account auto-authentication when. Primarily used for non-CI runs. Default 'false'. +# # tgz_file: if upload is not latest, specify the relative path to tarball to upload. +# function gcs_upload_asset() { +# local $* - disable_svcacct_auth="${disable_svcacct_auth:-false}" - service_account_id="${service_account_id:-}" - service_account_keyfile="${service_account_keyfile:-/tmp/keyfile.json}" - project_name="${project_name:-}" +# disable_svcacct_auth="${disable_svcacct_auth:-false}" +# service_account_id="${service_account_id:-}" +# service_account_keyfile="${service_account_keyfile:-/tmp/keyfile.json}" +# project_name="${project_name:-}" - if [[ -z "${disable_svcacct_auth}" ]]; then - if [[ -z "${service_account_id}" || -z "${project_name}" ]]; then - printf 'ERROR: gce_upload_asset():: must specify service_account_id and project_name!' 1>&2 - return 1 - fi - fi +# if [[ -z "${disable_svcacct_auth}" ]]; then +# if [[ -z "${service_account_id}" || -z "${project_name}" ]]; then +# printf 'ERROR: gce_upload_asset():: must specify service_account_id and project_name!' 1>&2 +# return 1 +# fi +# fi - version="${version:-''}" - if [[ -z "${version}" ]]; then - printf 'ERROR: gce_upload_asset(): must specify version!' 1>&2 - return 1 - fi +# version="${version:-''}" +# if [[ -z "${version}" ]]; then +# printf 'ERROR: gce_upload_asset(): must specify version!' 1>&2 +# return 1 +# fi - upload_source="${upload_source:-/upload}" - upload_target="${upload_target:-gs://${project_name}/}" - is_latest="${is_latest:-false}" +# upload_source="${upload_source:-/upload}" +# upload_target="${upload_target:-gs://${project_name}/}" +# is_latest="${is_latest:-false}" - if [ "false" == "${is_latest}" ]; then - if [[ -z "${tgz_file}" ]]; then - printf 'ERROR: is_latest requires tgz_file!' 1>&2 - return 1 - fi - fi +# if [ "false" == "${is_latest}" ]; then +# if [[ -z "${tgz_file}" ]]; then +# printf 'ERROR: is_latest requires tgz_file!' 1>&2 +# return 1 +# fi +# fi - gzip_settings='html,js,css,xml,txt,map,svg,ttf,woff,woff2' - cache_settings='Cache-Control:no-cache,must-revalidate' +# gzip_settings='html,js,css,xml,txt,map,svg,ttf,woff,woff2' +# cache_settings='Cache-Control:no-cache,must-revalidate' - if [ "false" == "${disable_svcacct_auth}" ]; then - runCmd gcloud auth activate-service-account "${service_account_id}" --key-file "${service_account_keyfile}" --project "${project_name}" - else - echo "INFO: Automatic Service Account auth has been disabled. Falling back to existing account auth..." - fi +# if [ "false" == "${disable_svcacct_auth}" ]; then +# runCmd gcloud auth activate-service-account "${service_account_id}" --key-file "${service_account_keyfile}" --project "${project_name}" +# else +# echo "INFO: Automatic Service Account auth has been disabled. Falling back to existing account auth..." +# fi - if [ "false" == "${is_latest}" ]; then - runCmd gsutil -m cp "${tgz_file} ${upload_target}" - runCmd gsutil -m cp -z "${gzip_settings}" -R "${upload_source} ${upload_target}" - else - runCmd gsutil -h "$cache_settings" -m cp -z "$gzip_settings" -R "${upload_source} ${upload_target}" - #sleep 5 - #runCmd gsutil -h "$cache_settings" -m rsync -C -c -r -d "${upload_source} ${upload_target}/${version}" - fi -} +# if [ "false" == "${is_latest}" ]; then +# runCmd gsutil -m cp "${tgz_file} ${upload_target}" +# runCmd gsutil -m cp -z "${gzip_settings}" -R "${upload_source} ${upload_target}" +# else +# runCmd gsutil -h "$cache_settings" -m cp -z "$gzip_settings" -R "${upload_source} ${upload_target}" +# #sleep 5 +# #runCmd gsutil -h "$cache_settings" -m rsync -C -c -r -d "${upload_source} ${upload_target}/${version}" +# fi +# }