Skip to content

Commit

Permalink
Auto-update the staging tag
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed May 12, 2024
1 parent eaf386f commit 8de9eea
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions .github/workflows/update-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,33 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Update action.yml if needed
run: |
set -x
curl -s https://api.github.com/repos/rui314/mold/releases/latest > info
RELEASE_TAG=$(jq -r .tag_name info | sed 's/^v//')
RELEASE_DATE=$(jq -r .published_at info)
CURRENT_TAG=$(grep default: action.yml | head -1 | cut -d "'" -f 2)
curl -s https://api.github.com/repos/rui314/mold/releases/latest > info
RELEASE_TAG=$(jq -r .tag_name info | sed 's/^v//')
echo "$RELEASE_TAG" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'
if [ $CURRENT_TAG = $RELEASE_TAG ]; then
echo "action.yml is already up to date"
elif [ $(date +%s) -lt $(date -d "$RELEASE_DATE + 7 days" +%s) ]; then
echo "still in grace period"
else
# Update the default version and tag that commit as `staging`
if [ $CURRENT_TAG != $RELEASE_TAG ]; then
sed -i "s/default: '.*'/default: '$RELEASE_TAG'/" action.yml
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git commit -am "Update default version to $RELEASE_TAG"
git push
git tag -f v1
git tag -f staging
git push -f --tags
fi
# If `staging` is 7 days old, tag it as `v1` as well
if [ $(git rev-parse v1) != $(git rev-parse staging) -a \
$(git show -s --format=%ct staging) -lt $(date -d '7 days ago' +%s) ]; then
git tag -f v1 $(git rev-parse staging)
git push -f --tags
fi

0 comments on commit 8de9eea

Please sign in to comment.