From cdad90d11b5895341e2fe72f6aaeb9f715c89d64 Mon Sep 17 00:00:00 2001 From: Leonid Makarov Date: Mon, 22 Nov 2021 17:28:27 -0800 Subject: [PATCH] Switched to Github Actions --- .github/workflows/default.yaml | 65 ++++++++++++++++++++++++++++++++++ .travis.yml | 32 ----------------- scripts/upload-to-s3.sh | 13 +++---- 3 files changed, 72 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/default.yaml delete mode 100644 .travis.yml diff --git a/.github/workflows/default.yaml b/.github/workflows/default.yaml new file mode 100644 index 0000000..8f84657 --- /dev/null +++ b/.github/workflows/default.yaml @@ -0,0 +1,65 @@ +name: Publish Templates + +on: + push: + branches: + - "**" + tags: + - 'v*.*.*' + workflow_dispatch: # Allow manually triggering a build + +defaults: + run: + shell: bash + +env: + AWS_REGION: us-east-2 + AWS_ACCESS_KEY_ID: AKIAIPJXMNOEV65OMURA + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + S3_BUCKET: docksal-aws-templates + UPLOAD_DIR: sandbox-server + LOCAL_DIR: build + +jobs: + aws-templates: + name: "Publish: ${{ matrix.template }} template" + runs-on: ubuntu-20.04 + + strategy: + fail-fast: false # Don't cancel other jobs if one fails + matrix: + template: + - basic + - advanced + + steps: + - + name: Checkout + uses: actions/checkout@v2 +# - +# name: Environment variables +# run: | +# # Export variables for further steps +# echo "GIT_SHA7=${GITHUB_SHA:0:7}" >> $GITHUB_ENV +# echo "BUILD_CONTEXT=${VERSION:-.}" >> ${GITHUB_ENV} +# echo "BUILD_IMAGE_TAG=${IMAGE}:${VERSION_PREFIX}${VERSION}build" >> ${GITHUB_ENV} +# - +# name: Install AWS CLI +# run: | +# curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" +# unzip awscliv2.zip +# sudo ./aws/install + - + name: Build and publish template + env: + TEMPLATE_TYPE: ${{ matrix.template }} + run: | + cd aws-cloudformation && ./scripts/bash2yaml startup-${TEMPLATE_TYPE}.sh tpl-${TEMPLATE_TYPE}.yaml + aws cloudformation package --template-file template.yaml --s3-bucket null --output-template-file package.json --use-json + mkdir -p ${LOCAL_DIR} && mv -f package.json ${LOCAL_DIR}/${TEMPLATE_TYPE}.json + tmp=$(basename $(mktemp -u)) + aws s3 cp ${LOCAL_DIR}/${TEMPLATE_TYPE}.json s3://${S3_BUCKET}/${tmp} --acl public-read + res=$(aws cloudformation validate-template --region ${AWS_REGION} --template-url https://${S3_BUCKET}.s3.amazonaws.com/${tmp} || echo "error") + aws s3 rm s3://${S3_BUCKET}/${tmp} + if [ "${res}" == "error" ]; then exit 1; fi + ${GITHUB_WORKSPACE}/scripts/upload-to-s3.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2c4bd95..0000000 --- a/.travis.yml +++ /dev/null @@ -1,32 +0,0 @@ -# Use python, since we install and use aws cli during the build -language: python -python: - - "3.6" - -env: - global: - - AWS_REGION=us-east-2 - - AWS_ACCESS_KEY_ID=AKIAIPJXMNOEV65OMURA - # Encrypted AWS_SECRET_ACCESS_KEY - - secure: "KGqbZdK65Z/fwuM8XkIO7awap+hastKvpAXJPe1FvwwZ9QGK+t9ZDljyIN8oSZdEPH4te7opo5D5LxNVVbFuTfnQ4P3Mikl7aOoGQi39wx5XmBueeQB+r/fl1GjkOoRcHyLmRRbeP4Ux/VDG2cCNUsS9q/s6kqsf8k0RmcpDMn0tBef/CixdnTfoQxO8QOgDCoBt+ErBamgt/HFWM89bw4uaehXwoevgArVkaiFyyJv3xBpKRAWKYPuwxCc9iadbb13SiPbs5qx0lQulrYLzf3qkQKBBJRGAPysC7uITW10TY/KjxmHA4S6+Z67P5GK5khZ55xsC86gz0fgWHFCdflbu46kS2bkAozEf9HnU3cDV3sHMgPyIOaAgGwmYjcDjwE+oxa54sTfzEwZ1yAKY3twwDiKue/4hdaHVknoWUJdjL7s5fOS3XXl3g8pHsRvzAx9XO8ZAOv7n2Pf0UvGbgklbTgDQO+Vvi7jDJb1yXGT6o9YFTpazpj5R3kU1Nf3V28zNQ8/OGqKssKghgT/9Cm1DqZIWWiPHmbkF6Q7e/HBSgTLaRd/PI//C/pSlc25TO/vQ+hBoqdxZ/1FCDDiCpLCXxd1b33ea3HUKBtmKKtSWDYGo6VVI8X+PCx7DvzpWIX85xgLhvloTUeNUL4ly/dcVhuEDiq5eWGHdcw20NmY=" - - S3_BUCKET="docksal-aws-templates" - - UPLOAD_DIR="sandbox-server" - - LOCAL_DIR="build" - - matrix: - - TEMPLATE_TYPE=basic - - TEMPLATE_TYPE=advanced - -install: - - pip install awscli --upgrade - -script: - - cd aws-cloudformation && ./scripts/bash2yaml startup-${TEMPLATE_TYPE}.sh tpl-${TEMPLATE_TYPE}.yaml - - aws cloudformation package --template-file template.yaml --s3-bucket null --output-template-file package.json --use-json - - mkdir -p ${LOCAL_DIR} && mv -f package.json ${LOCAL_DIR}/${TEMPLATE_TYPE}.json - - tmp=$(basename $(mktemp -u)) - - aws s3 cp ${LOCAL_DIR}/${TEMPLATE_TYPE}.json s3://${S3_BUCKET}/${tmp} --acl public-read - - res=$(aws cloudformation validate-template --region ${AWS_REGION} --template-url https://${S3_BUCKET}.s3.amazonaws.com/${tmp} || echo "error") - - aws s3 rm s3://${S3_BUCKET}/${tmp} - - if [ "${res}" == "error" ]; then exit 1; fi - - ${TRAVIS_BUILD_DIR}/scripts/upload-to-s3.sh diff --git a/scripts/upload-to-s3.sh b/scripts/upload-to-s3.sh index 193ad9b..42d2aab 100755 --- a/scripts/upload-to-s3.sh +++ b/scripts/upload-to-s3.sh @@ -4,28 +4,29 @@ is_edge () { - [[ "${TRAVIS_BRANCH}" == "develop" ]] + [[ "${GITHUB_REF}" == "refs/heads/develop" ]] } is_stable () { - [[ "${TRAVIS_BRANCH}" == "master" ]] + [[ "${GITHUB_REF}" == "refs/heads/master" ]] } is_release () { - [[ "${TRAVIS_TAG}" != "" ]] + [[ "${GITHUB_REF}" =~ "refs/tags/" ]] } # Check whether the current build is for a pull request is_pr () { - [[ "${TRAVIS_PULL_REQUEST}" != "false" ]] + # GITHUB_HEAD_REF is only set for pull requests + [[ "${GITHUB_HEAD_REF}" != "" ]] } # ---------------------------- # # Extract version parts from release tag -IFS='.' read -a ver_arr <<< "$TRAVIS_TAG" +IFS='.' read -a ver_arr <<< ${GITHUB_REF#refs/tags/} VERSION_MAJOR=${ver_arr[0]#v*} # 2.7.0 => "2" VERSION_MINOR=${ver_arr[1]} # "2.7.0" => "7" VERSION_HOTFIX=${ver_arr[2]} # "2.7.0" => "0" @@ -35,7 +36,7 @@ STABLE_UPLOAD_DIR=${UPLOAD_DIR}/stable RELEASE_UPLOAD_DIR_MAJOR=${UPLOAD_DIR}/v${VERSION_MAJOR} RELEASE_UPLOAD_DIR_MINOR=${UPLOAD_DIR}/v${VERSION_MAJOR}.${VERSION_MINOR} RELEASE_UPLOAD_DIR_HOTFIX=${UPLOAD_DIR}/v${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_HOTFIX} -BRANCH_UPLOAD_DIR=${UPLOAD_DIR}/branch/${TRAVIS_BRANCH} +BRANCH_UPLOAD_DIR=${UPLOAD_DIR}/branch/${GITHUB_REF#refs/heads/} # Skip pull request is_pr && exit 0