Skip to content

adding fetch for remote tags #3

adding fetch for remote tags

adding fetch for remote tags #3

Workflow file for this run

name: MIO Release Pipeline
on:
push:
permissions:
contents: write
packages: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Read version from file
id: version
run: |
VERSION=$(cat VERSION)
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: check_tag
run: |
git fetch --tags
if git tag -l v${{ steps.version.outputs.VERSION }} | grep -q v${{ steps.version.outputs.VERSION }}; then
echo "TAG_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "TAG_EXISTS=false" >> $GITHUB_OUTPUT
fi
- name: Create release tag
if: steps.check_tag.outputs.TAG_EXISTS == 'false'
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git tag -a v${{ steps.version.outputs.VERSION }} -m "Release ${{ steps.version.outputs.VERSION }}"
git push origin v${{ steps.version.outputs.VERSION }}
- name: Create tar archive
run: |
tar -czf /tmp/mio-${{ steps.version.outputs.VERSION }}.tar.gz \
--exclude=.git \
--exclude=.github \
--exclude=build \
--exclude=.gitignore \
--exclude=.clang-format \
--exclude=.clang-tidy \
.
- name: Create GitHub Release
if: steps.check_tag.outputs.TAG_EXISTS == 'false'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.VERSION }}
release_name: Release ${{ steps.version.outputs.VERSION }}
body: |
Release of MIO ${{ steps.version.outputs.VERSION }}
draft: false
prerelease: false
- name: Get existing release
if: steps.check_tag.outputs.TAG_EXISTS == 'true'
id: get_release
uses: actions/github-script@v7
with:
script: |
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
});
const release = releases.data.find(r => r.tag_name === 'v${{ steps.version.outputs.VERSION }}');
if (release) {
core.setOutput('upload_url', release.upload_url);
}
- name: Upload tar archive to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.check_tag.outputs.TAG_EXISTS == 'false' && steps.create_release.outputs.upload_url || steps.get_release.outputs.upload_url }}
asset_path: /tmp/mio-${{ steps.version.outputs.VERSION }}.tar.gz
asset_name: mio-${{ steps.version.outputs.VERSION }}.tar.gz
asset_content_type: application/gzip