name: Build and Deploy Hugo Site on: push: branches: - main env: HUGO_VERSION: '0.121.2' GO_VERSION: '1.20.5' NODE_VERSION: '20.0.0' jobs: buildAndDeploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.4.0 - name: env-toml-file uses: SebRollen/toml-action@v1.2.0 id: read_toml with: file: 'hugo.toml' field: 'params.environment' - name: Echo environment run: echo "Environment is ${{ steps.read_toml.outputs.value }}" - name: Install Go run: | curl -LO "https://dl.google.com/go/go${{ env.GO_VERSION }}.linux-amd64.tar.gz" tar -C /usr/local -xzf go${{ env.GO_VERSION }}.linux-amd64.tar.gz echo "export PATH=$PATH:/usr/local/go/bin" >> $GITHUB_ENV rm go${{ env.GO_VERSION }}.linux-amd64.tar.gz go version - name: Cache Go modules uses: actions/cache@v3 with: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go- - name: Set up Node.js uses: actions/setup-node@v4.0.2 with: node-version: '20' cache: 'npm' - name: Install npm dependencies run: npm install - name: Cache Node modules uses: actions/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node- - name: Install Hugo run: | curl -LO "https://github.com/gohugoio/hugo/releases/download/v${{ env.HUGO_VERSION }}/hugo_extended_${{ env.HUGO_VERSION }}_Linux-64bit.tar.gz" tar -xvf hugo_extended_${{ env.HUGO_VERSION }}_Linux-64bit.tar.gz mv hugo /usr/local/bin/ rm hugo_extended_${{ env.HUGO_VERSION }}_Linux-64bit.tar.gz hugo version - name: Setup Project run: npm run project-setup - name: Build Hugo site run: hugo --minify - name: Setup rsync run: apt-get update && apt-get install -y rsync - name: Setup SSH Key uses: webfactory/ssh-agent@v0.5.3 with: ssh-private-key: ${{ secrets.VFO_SSH_KEY }} - name: Deploy to Development if: steps.read_toml.outputs.value == 'development' run: | echo "Running steps for Development Environment" rsync -avz --delete ./public/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/${{ secrets.DEVELOPMENT_PATH }} env: RSYNC_RSH: 'ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no' - name: Deploy to Production if: steps.read_toml.outputs.value == 'production' run: | echo "Running steps for Production Environment" rsync -avz --delete ./public/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/${{ secrets.PRODUCTION_PATH }} env: RSYNC_RSH: 'ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no'