Hugo
Hugo

Reputation: 651

How to use latest release tag in GitHub Actions?

I would like to control releases by creating release tags in GitHub such as:

name: deploy-live

on:
  push:
    tags:
      - release-v*

But also run deployments to re-build my static website using a Webhook which takes the latest release tag (and not include any development work after the latest release tag):

name: deploy-live

on:
  push:
    tags:
      - release-v*
  repository_dispatch:
    types:
      - prismic_content_update

Currently, this will re-build the site from the main branch including all changes since the last release tag. Is there a way to reset the HEAD (excluding changes) to the latest release tag before deploying?

Upvotes: 3

Views: 6443

Answers (1)

Hugo
Hugo

Reputation: 651

I've found a way to solve this problem with the following workflow:

name: deploy-live

on:
  push:
    tags:
      - release-v*
  repository_dispatch:
    types:
      - prismic_content_update

concurrency: deploy-live

jobs:
  deploy:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [ubuntu-latest]
        node: [14]

    steps:
      - name: Checkout
        uses: actions/checkout@master
        with:
          fetch-depth: 0

      - name: Checkout latest release tag
        run: |
          LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
          git checkout $LATEST_TAG

Upvotes: 10

Related Questions