feat: add Generate Project Key, and don't generate it by default #18
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: Deploy Script | |
on: | |
workflow_dispatch: | |
push: | |
branches: [main, develop] | |
release: | |
types: [published] | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install clasp | |
id: install-clasp | |
run: sudo npm install @google/[email protected] -g | |
- name: Write CLASPRC_JSON secret to .clasprc.json file | |
id: write-clasprc | |
run: | | |
echo '${{ secrets.CLASPRC_JSON }}' > ~/.clasprc.json | |
echo '{"scriptId":"${{ secrets.SCRIPT_ID }}"}' > .clasp.json | |
- name: Validate .clasprc.json content | |
id: validate-clasprc | |
run: | | |
if jq -e . ~/.clasprc.json >/dev/null 2>&1; then | |
echo "Valid JSON in .clasprc.json" | |
else | |
echo "Invalid JSON in .clasprc.json" | |
exit 1 | |
fi | |
- name: Check .clasp.json and .clasprc.json content | |
id: check-clasp-files | |
run: | | |
echo "Content of .clasp.json:" | |
cat .clasp.json | |
echo "Content of ~/.clasprc.json (masked):" | |
sed 's/.*/"[MASKED]"/' ~/.clasprc.json | |
- name: Check clasp login status | |
id: clasp_login | |
run: | | |
if clasp login --status; then | |
echo "Clasp login successful" | |
else | |
echo "Clasp login failed. Attempting to refresh token..." | |
clasp login --no-localhost | |
fi | |
- name: Save current .clasp.json contents to CLASPRC_JSON_FILE environment variable | |
id: save-clasprc | |
run: | | |
echo ::add-mask::$(cat ~/.clasp.json | jq -c) | |
echo "CLASPRC_JSON_FILE=$(cat ~/.clasp.json | jq -c)" >> $GITHUB_ENV | |
- name: Save CLASPRC_JSON_FILE environment variable to CLASPRC_JSON repo secret | |
id: set-clasprc-secret | |
uses: hmanzur/[email protected] | |
with: | |
name: "CLASPRC_JSON" | |
value: ${{ env.CLASPRC_JSON_FILE }} | |
repository: ${{ github.repository }} | |
token: ${{ secrets.REPO_ACCESS_TOKEN }} | |
- name: Checkout repo | |
id: checkout-repo | |
if: ${{github.event_name != 'schedule' }} | |
uses: actions/checkout@v4 | |
- name: Set scriptId in .clasp.json file | |
id: set-script-id | |
if: ${{ github.event_name != 'schedule' && env.SCRIPT_ID }} | |
run: jq '.scriptId = "${{ env.SCRIPT_ID }}"' .clasp.json > /tmp/.clasp.json && mv /tmp/.clasp.json .clasp.json | |
env: | |
SCRIPT_ID: ${{ secrets.SCRIPT_ID }} | |
- name: Push script to scripts.google.com | |
id: clasp-push | |
if: ${{ github.event_name != 'schedule'}} | |
run: clasp push -f | |
- name: Deploy Script | |
id: clasp-deploy | |
if: ${{env.DEPLOYMENT_ID && (github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/main'))}} | |
run: clasp deploy -i "$DEPLOYMENT_ID" -d "$GITHUB_REF" | |
env: | |
DEPLOYMENT_ID: ${{ secrets.DEPLOYMENT_ID }} |