TravisCI 不上传使用 grunt 创建的文件

TravisCI 不上传使用 grunt 创建的文件

下面是我的 .travis.yml,我使用 grunt 编译我的 sass,并最小化 js 和图像,这些文件似乎工作正常,但是这些文件都没有部署到 Elastic Beanstalk。我skip_cleanup: true根据文档添加了应该可以解决这个问题但无济于事。

language: php

before_install:
  - nvm install 0.10.38
  - npm set progress=false
  - npm install -g grunt-cli grunt grunt-bower -loglevel=error
  - gem install dpl

script:
  - echo "success"

before_deploy:
  - cd ${TRAVIS_BUILD_DIR}/wp-content/themes/myapp && npm install --loglevel=error
  - cd ${TRAVIS_BUILD_DIR}/wp-content/themes/myapp && grunt build
  - cd ${TRAVIS_BUILD_DIR}
  - ls ${TRAVIS_BUILD_DIR}/wp-content/themes/myapp

env:
  - ELASTIC_BEANSTALK_LABEL=$TRAVIS_COMMIT

deploy:
  skip_cleanup: true
  provider: elasticbeanstalk
  region: us-east-1
  app: App
  env: app-staging
  bucket-name: elasticbeanstalk-us-east-1-AAAAAAAA123
  access_key_id: ${STAGING_AWS_ACCESS_KEY_ID}
  secret_access_key: ${STAGING_AWS_SECRET_KEY}  
  on:
    branch: staging

答案1

我从来没有找到仅使用 travis 来构建和运送的答案,我不得不在 Travis 运行 grunt build 后手动创建一个 zip 文件并使用 awscli 将其上传到 s3 并触发 EB 部署。

.travis.yml

language: node_js
node_js:
  - 0.10

before_install:
  - sudo pip install awscli
  - ls /usr/local/bin/
  - which aws
  - npm set progress=false
  - npm install -g grunt-cli grunt grunt-bower -loglevel=error

script:
  - echo "success"

before_deploy:
  - cd ${TRAVIS_BUILD_DIR}/wp-content/themes/mytheme && npm install --loglevel=error
  - cd ${TRAVIS_BUILD_DIR}/wp-content/themes/mytheme && grunt build
  - cd ${TRAVIS_BUILD_DIR}
  - echo $(git rev-parse --short HEAD) >> /tmp/version
  - cd ${TRAVIS_BUILD_DIR} && zip -0 /tmp/travisci-$(cat /tmp/version).zip -r ./ -x "wp-content/themes/mytheme/node_modules/*" "*.git*" > /dev/null 
  - chmod +x scripts/deploy/production.sh

deploy:
  - provider: script
    skip_cleanup: true
    script: scripts/deploy/production.sh
    on:
      branch: master

脚本/部署/production.sh

mkdir ~/.aws
touch ~/.aws/config
chmod 600 ~/.aws/config
echo "[default]" > ~/.aws/config
echo "aws_access_key_id = $AWS_ACCESS_KEY_ID" >> ~/.aws/config
echo "aws_secret_access_key = $AWS_SECRET_ACCESS_KEY" >> ~/.aws/config
cp ~/.aws/config ~/.aws/credentials
aws s3 cp /tmp/travisci-*.zip s3://elasticbeanstalk-us-east-1-1234567890/
aws elasticbeanstalk create-application-version --region us-east-1 --application-name "app" --version-label `cat /tmp/version` --source-bundle S3Bucket="elasticbeanstalk-us-east-1-1234567890",S3Key="travisci-`cat /tmp/version`.zip"
aws elasticbeanstalk update-environment --region us-east-1 --environment-name "app-production" --version-label `cat /tmp/version`

答案2

我认为这是因为部署工具使用git ls-files选择要部署的文件。要解决这个问题,您可以在部署之前使用,也可以尝试即时git add -f ignored_folder修改。.gitignore

相关内容