Jump to content

GitHub Workflow Help


DanRz

Recommended Posts

Hey!

I am using the following GitHub workflow to publish to FTP when a new tag is pushed however I need to alter it to get the tag name and update the .env file on the server with the new version... I just can't work out how to do it...

on:
  push:
    tags:
    - '*'
name: 🚀 Deploy app on new tag
jobs:
  web-deploy:
    name: 🎉 Deploy
    runs-on: ubuntu-latest
    steps:
    - name: 🚚 Get latest code
      uses: actions/checkout@v3

    - name: 📂 Sync files
      uses: SamKirkland/FTP-Deploy-Action@4.3.3
      with:
        server: ftp.domain.com
        username: XXX
        password: ${{ secrets.ftp_pwd }}

    - name: 🔐 Set Env Version
      id: vars
      run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
    - name: 🔏 Write Env Version
      env:
        RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
      run: |
        echo $RELEASE_VERSION
        echo ${{ steps.vars.outputs.tag }}

Any help would be appreciated.

Dan

Link to comment
Share on other sites

I haven't used the SamKirkland/FTP-Deploy-Action action so I'm not sure exactly how it works, but it kinda looks like you're copying the files to the ftp server before you make the updates to the file. Use stream editor in your workflow steps to modify the .env, then place the modified files on the server.

If you set up a .env.example file in the repo with a value like so:

VERSION={{VERSION}}

You'll be able to run this in your workflow (assuming VERSION is a variable in your repository):

- run: |
	cp .env.example .env
	sed -i 's/{{VERSION}}/${{ vars.VERSION }}/g' .env

 

Edited by maxxd
Link to comment
Share on other sites

Thanks for your reply. I have managed to fix this :) see code below;

on:
  push:
    branches: [ development ]
name: 🚀 Deploy app on new tag
jobs:
  web-deploy:
    name: 🎉 Deploy
    runs-on: ubuntu-latest
    steps:
    - name: 🚚 Get latest code
      uses: actions/checkout@v3

    - name: 🏷️ Get Current Tag
      id: vars
      run:  echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT

    - name: 🔏 Write Tag Version
      env:
        RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
      run: |
        echo $RELEASE_VERSION

    - name: 🗃️ Make env File
      uses: SpicyPizza/create-envfile@v1.3
      with:
        envkey_APP_ENV: "live"
        envkey_APP_STATUS: "1"
        envkey_APP_VERSION: ${{ steps.vars.outputs.tag }}

    - name: 📂 Sync files
      uses: SamKirkland/FTP-Deploy-Action@4.3.3
      with:
        server: FTPSERVER
        username: USERNAME
        password: ${{ secrets.ftp_pwd }}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.