Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 4

Checkout with code from the latest release

Solved! Go to Solution.

I've built a workflow that is triggered by calling GitHub API.

The idea is to deploy the latest release to FTP server on demand.

on:
  repository_dispatch

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:

    - name: Checkout
      uses: actions/checkout@v1

    - name: Install Dependencies
      run: |
        npm install

    - name: Test
      run: |
        npm run test:ci
      
    - name: Build
      run: |
        npm run build
        
        
    - name: Deploy to FTP
      uses: SamKirkland/FTP-Deploy-Action@2.0.0
      env:
        FTP_SERVER: ${{ secrets.FTP_SERVER }}
        FTP_USERNAME: ${{ secrets.FTP_USERNAME }}
        FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
        REMOTE_DIR: site/wwwroot
        LOCAL_DIR: build
        METHOD: ftp
        ARGS: --no-empty-dirs --delete

above code works great, the problem is that it will always deploy latest code from my master branch.

How can I specify that I want to deploy code from the latest release? I'm always creating a tag when I create a release, so I'd like to be able to do a checkout for the latest tag or release.

 

Is this possible?

3 Replies
Highlighted
GitHub Staff
Message 2 of 4

Re: Checkout with code from the latest release

You could trigger when a released is published and then checkout would be the ref of the published release.

 

on:
  release:
    types: [published]
Highlighted
Solution
GitHub Partner
Message 3 of 4

Re: Checkout with code from the latest release

Hi @Misiu ,

 

You can specify the 'tag' value in the 'actions/checkout' args, code sample as below:

      - name: tagcheckout
        uses: actions/checkout@v2
        with:
          ref: v1.1.9

It will checkout the code which tagged with v1.1.9. Please refer to the usage of 'actions/checkout' for more details.

Besides, you can use rest api to get the latest release, parse the release tagname to the 'ref' value then. Code sample as below, it will automatically get the latest release tag and checkout the release code:

    steps:
      - name: get latest release with tag
        id: latestrelease
        run: |
          echo "::set-output name=releasetag::$(curl -s https://api.github.com/repos/weide-zhou/ticket13/releases/latest | jq '.tag_name' | sed 's/\"//g')"
      - name: confirm release tag
        run: |
          echo ${{ steps.latestrelease.outputs.releasetag }}
      - name: tagcheckout
        uses: actions/checkout@v2
        with:
          ref: ${{ steps.latestrelease.outputs.releasetag }}

checkoutlatestrelease.png

Thanks.

Highlighted
Copilot Lvl 3
Message 4 of 4

Re: Checkout with code from the latest release

I've tried your code, and it works for public repo, but I have a private repo. How should I modify curl request to pass authentication token?

 

when I do a request with Postman (and pass token in the header) I get the correct response. My tag looks like this:

 "2020-03-18-05"

 

Got it. I had to add:

--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}'