Create Release on Manifest Update #3
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: Create Release on Manifest Update | |
on: | |
push: | |
paths: | |
- 'manifest.json' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
create_tag: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # 获取所有历史,以便检查 tag 是否存在 | |
- name: Get version from manifest.json | |
id: get_version | |
run: echo "version=$(jq -r .version manifest.json)" >> $GITHUB_OUTPUT | |
- name: Check if tag exists | |
id: check_tag | |
run: | | |
TAG_EXISTS=$(git tag -l "v${{ steps.get_version.outputs.version }}") | |
if [[ -n "$TAG_EXISTS" ]]; then | |
echo "::set-output name=tag_exists::true" | |
echo "Tag v${{ steps.get_version.outputs.version }} already exists." | |
else | |
echo "::set-output name=tag_exists::false" | |
fi | |
- name: Create and push tag | |
if: steps.check_tag.outputs.tag_exists == 'false' | |
run: | | |
git config --global user.name 'GitHub Actions Bot' | |
git config --global user.email '[email protected]' | |
git tag "v${{ steps.get_version.outputs.version }}" | |
git push origin "v${{ steps.get_version.outputs.version }}" | |
build_and_release: | |
needs: create_tag | |
if: needs.create_tag.outputs.tag_exists == 'false' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Get version from manifest.json | |
id: get_version | |
run: echo "version=$(jq -r .version manifest.json)" >> $GITHUB_OUTPUT | |
- name: Zip extension | |
run: | | |
zip -r rename-tab-v${{ steps.get_version.outputs.version }}.zip . -x "*.git*" -x ".github/*" | |
- name: Create Release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: "v${{ steps.get_version.outputs.version }}" | |
release_name: Release v${{ steps.get_version.outputs.version }} | |
body: | | |
自动构建的 Release v${{ steps.get_version.outputs.version }} | |
draft: false | |
prerelease: false | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: rename-tab-v${{ steps.get_version.outputs.version }}.zip | |
asset_name: rename-tab-v${{ steps.get_version.outputs.version }}.zip | |
asset_content_type: application/zip |