Skip to content

Update push_event.yml #24

Update push_event.yml

Update push_event.yml #24

Workflow file for this run

name: Run Custom Script
on:
push:
branches:
- master
env:
PROJECT_ID: ${{ vars.APIFOXPROJECTID }}
ENVIRONMENT: dev
jobs:
runScript:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4.1.4
- name: Get last modified time
id: last-modified
run: |
LAST_MODIFIED=$(curl -s "https://api.github.com/repos/${GITHUB_REPOSITORY}/commits?path=hello.sh" \
| grep -m 1 'date' \
| sed -E 's/^[[:space:]]+"date": "(.*)",$/\1/')
echo "::set-output name=last_modified::${LAST_MODIFIED}"
- name: Display last modified time
run: |
echo "Last modified time: ${{ steps.last-modified.outputs.last_modified }}"
- name: Run custom script
run: |
ls -lh
echo "git log"
git log -1 --format="%ct" -- ./hello.sh
git log -2 --format="%ct" -- ./hello.sh
echo "system date"
date +%s
#cd path/to/script/directory
#echo "Hello World!"
# 执行脚本文件
echo ${{ vars.APIFOXPROJECTID}} #仓库的变量
echo ${{ secrets.APITOKEN }} #仓库密钥
echo ${{ vars.TESTSKEY }} # 测试不存在的vars会发生什么
echo ${{ env.PROJECT_ID }}
echo ${GITHUB_SHA:0:10}
echo "end"
sudo sh ./hello.sh
- name: Extract origin branch name # 发布到dev/test环境就拿分支;发布到prod环境就拿Tag
id: extract_origin_branch
shell: bash
run: |
if [ $ENVIRONMENT == "dev" ]
then
echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
elif [ $ENVIRONMENT == "test" ]
then
echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
else
echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/tags/})"
fi
- name: Extract branch name # 处理斜杠
id: extract_branch
shell: bash
run: |
echo ${{ steps.extract_origin_branch.outputs.branch }}
echo "##[set-output name=branch;]$(echo ${{ steps.extract_origin_branch.outputs.branch }} | sed 's/\//_/g')"
- name: Extract github sha # 拿github sha 并截取10位
id: extract_github_sha
shell: bash
run: |
echo ${GITHUB_SHA}
echo "##[set-output name=githubsha;]$(echo ${GITHUB_SHA:0:10})"
- name: Extract image tag # 提取镜像tag 命名规则 [分支名/Tag]_[GithubCommitSHA]
id: extract_image_tag
shell: bash
run: |
echo "##[set-output name=imagetag;]$(echo ${{ steps.extract_branch.outputs.branch }}_${{ steps.extract_github_sha.outputs.githubsha }})"