comment workflows.

pull/2681/head
Monet Lee 12 months ago
parent d1d70133ca
commit 5333129524

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