Skip to content

Instantly share code, notes, and snippets.

@platformsh-devrel
Created November 13, 2023 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save platformsh-devrel/c9591a7007f46b380b8cfd183b69b69d to your computer and use it in GitHub Desktop.
Save platformsh-devrel/c9591a7007f46b380b8cfd183b69b69d to your computer and use it in GitHub Desktop.
GitHub Actions workflow to only push Tags to Platform.sh
on:
push:
tags:
- '*'
jobs:
should-we-push:
runs-on: ubuntu-latest
outputs:
push: ${{ steps.do-push.outputs.push }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.repository.default_branch }}
- id: get-latest-tag
run: |
latestTag=$(git describe --abbrev=0 --tags)
echo "latest_tag=${latestTag}" >> $GITHUB_OUTPUT
- id: do-push
run: |
push="false"
if [[ "${{ github.ref_name }}" = "${{ steps.get-latest-tag.outputs.latest_tag }}" ]]; then
echo "::notice::We have a new tag to push to Platform.sh"
push="true"
fi
echo "push=${push}" >> $GITHUB_OUTPUT
we-should-push:
runs-on: ubuntu-latest
needs: should-we-push
if: needs.should-we-push.outputs.push == 'true'
env:
PLATFORMSH_CLI_TOKEN: ${{ secrets.PSH_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: |
echo "setting up the Platform.sh cli"
curl -fsSL https://raw.githubusercontent.com/platformsh/cli/main/installer.sh | bash
- run: |
echo "setting the remote project"
platform project:set-remote "${{ secrets.PROJID }}"
- run: |
echo "set up a new ssh cert"
platform ssh-cert:load --new --no-interaction
- run: |
pshWholeGitAddress=$(git remote get-url platform --push)
pshGitAddress=$(TMP=${pshWholeGitAddress#*@};echo ${TMP%:*})
echo "Adding psh git address ${pshGitAddress} to known hosts"
ssh-keyscan -t rsa "${pshGitAddress}" >> ~/.ssh/known_hosts
- run: |
echo "Pushing tag ${{ github.ref_name }} to Platform.sh..."
pshDefaultBranch=$(platform project:info default_branch)
git push platform refs/tags/${{ github.ref_name }}^{commit}:refs/heads/${pshDefaultBranch}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment