|
| 1 | +on: [push] |
| 2 | +jobs: |
| 3 | + build: |
| 4 | + name: Test |
| 5 | + runs-on: ubuntu-latest |
| 6 | + |
| 7 | + services: |
| 8 | + postgres: |
| 9 | + image: postgres |
| 10 | + ports: ['5432:5432'] |
| 11 | + env: |
| 12 | + POSTGRES_USER: test-a-bot |
| 13 | + POSTGRES_PASSWORD: toot |
| 14 | + POSTGRES_DATABASE: rubbish-heap |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Get Code |
| 18 | + uses: actions/checkout@v2 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + |
| 22 | + - name: Install Dependencies |
| 23 | + run: | |
| 24 | + sudo apt-get install ffmpeg -y |
| 25 | + sudo apt-get install youtube-dl |
| 26 | + |
| 27 | + - name: Fetch Ruby Version |
| 28 | + id: ruby_version |
| 29 | + run: echo "::set-output name=RUBY_VERSION::$(cat .ruby-version)" |
| 30 | + |
| 31 | + - name: Install Ruby |
| 32 | + uses: actions/setup-ruby/@v1 |
| 33 | + with: |
| 34 | + ruby-version: ${{ steps.ruby_version.outputs.RUBY_VERSION }} |
| 35 | + |
| 36 | + - name: Fetch Node Version |
| 37 | + id: node_version |
| 38 | + run: echo "::set-output name=NODE_VERSION::$(cat .nvmrc)" |
| 39 | + |
| 40 | + - name: Install Node |
| 41 | + uses: actions/setup-node@v1 |
| 42 | + with: |
| 43 | + node-version: ${{ steps.node_version.outputs.NODE_VERSION }} |
| 44 | + |
| 45 | + - name: Fetch Yarn Cache Directory |
| 46 | + id: yarn-cache-dir-path |
| 47 | + run: echo "::set-output name=dir::$(yarn cache dir)" |
| 48 | + |
| 49 | + - name: Configure Yarn Cache |
| 50 | + uses: actions/cache@v1 |
| 51 | + id: yarn-cache |
| 52 | + with: |
| 53 | + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} |
| 54 | + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} |
| 55 | + restore-keys: | |
| 56 | + ${{ runner.os }}-yarn- |
| 57 | +
|
| 58 | + - name: Install Node Packages |
| 59 | + run: yarn |
| 60 | + |
| 61 | + - name: Configure Ruby Cache |
| 62 | + uses: actions/cache@v1 |
| 63 | + with: |
| 64 | + path: vendor/bundle |
| 65 | + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} |
| 66 | + restore-keys: | |
| 67 | + ${{ runner.os }}-gems- |
| 68 | +
|
| 69 | + - name: Install Ruby Packages |
| 70 | + run: | |
| 71 | + gem install bundler |
| 72 | + bundle config path vendor/bundle |
| 73 | + bundle install --jobs 4 --retry 3 |
| 74 | +
|
| 75 | + - name: Build and Test with Rake |
| 76 | + env: |
| 77 | + DATABASE_URL: postgres://test-a-bot:toot@localhost/rubbish-heap |
| 78 | + RAILS_ENV: test |
| 79 | + run: | |
| 80 | + bundle exec rails db:setup |
| 81 | + bundle exec rails test |
| 82 | +
|
| 83 | + - name: Write Heroku Credentials |
| 84 | + env: |
| 85 | + NETRC: | |
| 86 | + machine api.heroku.com |
| 87 | + login ${{ secrets.HEROKU_USER }} |
| 88 | + password ${{ secrets.HEROKU_API_KEY }} |
| 89 | +
|
| 90 | + machine git.heroku.com |
| 91 | + login ${{ secrets.HEROKU_USER }} |
| 92 | + password ${{ secrets.HEROKU_API_KEY }} |
| 93 | +
|
| 94 | + run: echo $NETRC > ~/.netrc |
| 95 | + |
| 96 | + - name: Push to Heroku, Staging |
| 97 | + if: github.ref == 'refs/heads/master' |
| 98 | + run: | |
| 99 | + heroku git:remote --app ${{ secrets.STAGING_APP_NAME }} |
| 100 | + git push --force heroku HEAD:master |
| 101 | + |
| 102 | + - name: Push to Heroku, Production |
| 103 | + if: github.ref == 'refs/heads/production' |
| 104 | + run: | |
| 105 | + heroku git:remote --app ${{ secrets.PRODUCTION_APP_NAME }} |
| 106 | + git push --force heroku HEAD:master |
0 commit comments