v0.0.40 #13
Workflow file for this run
This file contains 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: Update Version File on Release | |
on: | |
release: | |
types: [created] | |
jobs: | |
update-version: | |
runs-on: ubuntu-latest | |
env: | |
TAG_VERSION: ${{ github.event.release.tag_name }} | |
steps: | |
# Step 1: Checkout the repository's code | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# Step 2: Set up Git with official account | |
- name: Set up Git | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
# Step 3: Switch to the main branch | |
- name: Switch to main branch | |
run: | | |
git checkout main | |
git pull origin main | |
# Step 4: Check and delete the existing tag (if present) | |
- name: Check and delete existing tag | |
run: | | |
if git rev-parse ${{ env.TAG_VERSION }} >/dev/null 2>&1; then | |
git tag -d ${{ env.TAG_VERSION }} # Delete local tag | |
git push --delete origin ${{ env.TAG_VERSION }} # Delete remote tag | |
fi | |
# Step 5: Update the version file | |
- name: Update version file | |
run: | | |
echo "${{ env.TAG_VERSION }}" > version/version # Write the version to the file | |
# Step 6: Commit and push changes to the main branch | |
- name: Commit and push changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git add version/version | |
git commit -m "Update version to ${{ env.TAG_VERSION }}" | |
git push origin main # Push to the main branch | |
# Step 7: Create and push the new tag | |
- name: Create and push new tag | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git tag ${{ env.TAG_VERSION }} # Create the new tag | |
git push origin ${{ env.TAG_VERSION }} # Push the tag to the remote repository | |
# Step 8: Find and publish the draft release | |
- name: Find and Publish Draft Release | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
// Get the list of releases | |
const releases = await github.rest.repos.listReleases({ | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
// Find the draft release where the title and tag_name are the same | |
const draftRelease = releases.data.find(release => | |
release.draft && release.name === release.tag_name | |
); | |
if (draftRelease) { | |
// Publish the draft release using the release_id | |
await github.rest.repos.updateRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
release_id: draftRelease.id, // Use release_id | |
draft: false | |
}); | |
core.info(`Draft Release ${draftRelease.tag_name} published successfully.`); | |
} else { | |
core.info("No matching draft release found."); | |
} |