Auto-tag on merge to main (#356) #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto Tag Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| env: | |
| TAG_PREFIX: "@openfn/apollo@" | |
| jobs: | |
| tag-release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check if tag exists | |
| id: check_tag | |
| run: | | |
| VERSION=$(jq -r '.version' package.json) | |
| TAG_NAME="${{ env.TAG_PREFIX }}${VERSION}" | |
| echo "tag_name=${TAG_NAME}" >> $GITHUB_OUTPUT | |
| if git ls-remote --tags origin | grep -q "refs/tags/${TAG_NAME}"; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| echo "Tag ${TAG_NAME} already exists" | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| echo "Tag ${TAG_NAME} does not exist" | |
| fi | |
| - name: Setup GH | |
| if: steps.check_tag.outputs.exists == 'false' | |
| run: | | |
| git config user.name "${{ secrets.GH_USER }}" | |
| git config user.email "${{ secrets.GH_EMAIL }}" | |
| - name: Generate and push tag | |
| if: steps.check_tag.outputs.exists == 'false' | |
| run: | | |
| TAG_NAME="${{ steps.check_tag.outputs.tag_name }}" | |
| git tag "${TAG_NAME}" | |
| git push origin "${TAG_NAME}" | |
| echo "Successfully created and pushed tag: ${TAG_NAME}" |