Checkout with code from the latest release

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.


    runs-on: ubuntu-latest

    - 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
        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?

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

    types: [published]

Hi @misiu ,

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

- name: tagcheckout
        uses: actions/checkout@v2
          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:

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



1 Like

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:


Got it. I had to add:

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