From f4dfaa87618c91bbe2be7ec9f3fb7889dd68baa2 Mon Sep 17 00:00:00 2001 From: graphemecluster Date: Wed, 8 Jan 2025 10:05:15 +0800 Subject: [PATCH] =?UTF-8?q?Extract=20=E2=80=9CPublish=20to=20COS=E2=80=9D?= =?UTF-8?q?=20into=20a=20composite=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/actions/publish-to-cos/action.yml | 30 +++++++++++++++++++++++ .github/workflows/build.yml | 21 +++------------- 2 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 .github/actions/publish-to-cos/action.yml diff --git a/.github/actions/publish-to-cos/action.yml b/.github/actions/publish-to-cos/action.yml new file mode 100644 index 0000000..8fde021 --- /dev/null +++ b/.github/actions/publish-to-cos/action.yml @@ -0,0 +1,30 @@ +name: Publish to Tencent Cloud COS +description: Publish static files to Tencent Cloud Object Storage + +inputs: + secret_id: + description: Tencent Cloud Secret ID + required: true + secret_key: + description: Tencent Cloud Secret Key + required: true + +runs: + using: composite + steps: + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install coscmd + run: pip install coscmd + shell: bash + + - name: Configure coscmd + run: coscmd config -a ${{ inputs.secret_id }} -s ${{ inputs.secret_key }} -b nk2028-1305783649 -r ap-guangzhou + shell: bash + + - name: Publish static files to COS + run: coscmd upload -rs --delete -f . /tshet-uinh-examples --ignore '*/.*,*/node_modules/*,./test/*,./build/*,./dist/*,./package.json,./package-lock.json,./eslint.config.js' + shell: bash diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index abd9478..4426f8c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,28 +35,15 @@ jobs: - name: Run tests run: npm test - # Publish to NPM - if: github.event_name == 'release' name: Publish to NPM run: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.npm_token }} - # Publish to Tencent Cloud COS - if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.repository == 'nk2028/tshet-uinh-examples' && github.ref == 'refs/heads/main') - name: Setup Python - uses: actions/setup-python@v5 + name: Publish to Tencent Cloud COS + uses: ./.github/actions/publish-to-cos with: - python-version: '3.11' - - if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.repository == 'nk2028/tshet-uinh-examples' && github.ref == 'refs/heads/main') - name: Install coscmd - run: pip install coscmd - - if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.repository == 'nk2028/tshet-uinh-examples' && github.ref == 'refs/heads/main') - name: Configure coscmd - env: - SECRET_ID: ${{ secrets.SecretId }} - SECRET_KEY: ${{ secrets.SecretKey }} - run: coscmd config -a $SECRET_ID -s $SECRET_KEY -b nk2028-1305783649 -r ap-guangzhou - - if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.repository == 'nk2028/tshet-uinh-examples' && github.ref == 'refs/heads/main') - name: Publish static files to COS - run: coscmd upload -rs --delete -f . /tshet-uinh-examples --ignore '*/.*,*/node_modules/*,./test/*,./build/*,./dist/*,./package.json,./package-lock.json,./eslint.config.js' + secret_id: ${{ secrets.SecretId }} + secret_key: ${{ secrets.SecretKey }}