From 9a30c779a547df5de5c50996810bde4370b404f9 Mon Sep 17 00:00:00 2001 From: Bean Date: Sat, 20 Jul 2024 11:11:47 +0800 Subject: [PATCH] ci: switch GitLab CI to GitHub Actions --- .github/workflows/release.yml | 68 +++++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 40 --------------------- 2 files changed, 68 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/release.yml delete mode 100644 .gitlab-ci.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ba6aa9c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,68 @@ +name: Deploy + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3 + + - name: Install dependencies + run: | + pip install hatch twine + + - name: Set DATE variable + run: echo "DATE=$(date +%Y.%-m.%-d)" >> $GITHUB_ENV + + - name: Display date + run: echo "date ${{ env.DATE }}" + + - name: Set initial TAG_NUMBER + run: echo "TAG_NUMBER=1" >> $GITHUB_ENV + + - name: Get last tag + id: get_last_tag + run: echo "LAST_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV + + - name: Display last tag + run: echo "last tag ${{ env.LAST_TAG }}" + + - name: Determine new tag + run: | + if [[ "${{ env.LAST_TAG }}" == *"${{ env.DATE }}"* ]]; then + echo "is today" + echo "${{ env.LAST_TAG##*. }}" + echo "TAG_NUMBER=$((${{ env.LAST_TAG##*. }} + 1))" >> $GITHUB_ENV + fi + echo "NEW_TAG=${{ env.DATE }}.${{ env.TAG_NUMBER }}" >> $GITHUB_ENV + + - name: Display new tag + run: echo "Creating tag ${{ env.NEW_TAG }}" + + - name: Create and push tag + run: | + git tag "${{ env.NEW_TAG }}" + git push origin "${{ env.NEW_TAG }}" + + - name: Update version with hatch + run: hatch version ${{ env.NEW_TAG }} + + - name: Build with hatch + run: hatch build + + - name: Upload to PyPI + env: + TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} + TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} + run: twine upload dist/* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 6e39054..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,40 +0,0 @@ -image: python:3 - -stages: - - deploy - -deploy: - stage: deploy - script: - - pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple - - pip install hatch twine - - - DATE=$(date +%Y.%m.%d) - - echo "date $DATE" - - TAG_NUMBER=1 - - LAST_TAG=$(git describe --tags --abbrev=0) - - echo "last tag $LAST_TAG" - - | - if [[ "$LAST_TAG" == *$DATE* ]]; then - echo "is today" - echo "${LAST_TAG##*.}" - TAG_NUMBER=$((${LAST_TAG##*.} + 1)) - fi - - NEW_TAG="$DATE.$TAG_NUMBER" - - echo "Creating tag $NEW_TAG" - - | - if ! git remote | grep -q "gitlab_origin"; then - git remote add gitlab_origin https://oauth2:${PUSH_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${CI_PROJECT_PATH} - fi - - git tag "$NEW_TAG" - - git push gitlab_origin "$NEW_TAG" - - - hatch version $NEW_TAG - - hatch build - - TWINE_USERNAME=gitlab-ci-token TWINE_PASSWORD=${CI_JOB_TOKEN} twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/* - - TWINE_USERNAME=${TWINE_USERNAME} TWINE_PASSWORD=${TWINE_PASSWORD} twine upload dist/* - rules: - - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH - - tags: - - nuc