Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhichang committed Dec 30, 2023
1 parent b9f2e97 commit 73cf52e
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: release

on:
schedule:
- cron: '0 * * * *' # schedule nightly build daily at midnight UTC
# The "create tags" trigger is specifically focused on the creation of new tags, while the "push tags" trigger is activated when tags are pushed, including both new tag creations and updates to existing tags.
create:
tags:
- "v*.*.*" # normal release
- "nightly" # the only one mutable tag

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Ensure workspace ownership
run: echo "chown -R $USER $GITHUB_WORKSPACE" && sudo chown -R $USER $GITHUB_WORKSPACE

# https://github.com/actions/checkout/blob/v3/README.md
- name: Check out code
uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.MY_DEPLOY_KEY }}

- name: Prepare release body
run: |
if [[ $GITHUB_EVENT_NAME == 'create' ]]; then
RELEASE_TAG=${GITHUB_REF#refs/tags/}
if [[ $RELEASE_TAG == 'nightly' ]]; then
PRERELEASE=true
else
PRERELEASE=false
fi
echo "Workflow triggered by create tag: $RELEASE_TAG"
else
RELEASE_TAG=nightly
PRERELEASE=true
echo "Workflow triggered by schedule"
fi
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV
RELEASE_DATETIME=$(date --rfc-3339=seconds)
cat <<EOF > release_template.md
Release $RELEASE_TAG created from $GITHUB_SHA at $RELEASE_DATETIME
EOF
envsubst < release_template.md > release_body.md
- name: Move the existing mutable tag
# https://github.com/softprops/action-gh-release/issues/171
run: |
if [[ $GITHUB_EVENT_NAME == 'schedule' ]]; then
# Determine if a given tag exists and matches a specific Git commit.
# actions/checkout@v3 fetch-tags doesn't work when triggered by schedule
git fetch --tags
if [ "$(git rev-parse -q --verify "refs/tags/$RELEASE_TAG")" = "$GITHUB_SHA" ]; then
echo "mutalbe tag $RELEASE_TAG exists and matchs $GITHUB_SHA"
else
git tag -f $RELEASE_TAG $GITHUB_SHA
git push -f origin $RELEASE_TAG:refs/tags/$RELEASE_TAG
echo "created/moved mutalbe tag $RELEASE_TAG to $GITHUB_SHA"
fi
fi
- name: Create or overwrite a release
# https://github.com/actions/upload-release-asset has been replaced by https://github.com/softprops/action-gh-release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.MY_GITHUB_TOKEN }} # Use the secret as an environment variable
prerelease: ${{ env.PRERELEASE }}
draft: false
tag_name: ${{ env.RELEASE_TAG }}
# The body field does not support environment variable substitution directly.
body_path: release_body.md
files: |
scripts/infinity-deps-ubuntu2310.sh
22 changes: 22 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: tests

on:
push:
branches: [ main ]
pull_request:
types: [ opened, synchronize, reopened, edited ]

jobs:
tests:
name: tests
# https://github.com/orgs/community/discussions/26261
if: contains(github.event.pull_request.labels.*.name, 'ci')
runs-on: ubuntu-latest
steps:
- name: Ensure workspace ownership
run: echo "chown -R $USER $GITHUB_WORKSPACE" && sudo chown -R $USER $GITHUB_WORKSPACE

- name: Check out code
uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.MY_DEPLOY_KEY }}

0 comments on commit 73cf52e

Please sign in to comment.