添加 其他自动cicd操作.txt
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 43s Details

This commit is contained in:
xiehaijun 2025-07-26 18:15:49 +00:00
parent 07c3257b28
commit 7dc755d257
1 changed files with 147 additions and 0 deletions

147
其他自动cicd操作.txt Normal file
View File

@ -0,0 +1,147 @@
name: demo pipeline
on:
push:
branches: [ "main" ]
jobs:
build:
runs-on: [ubuntu-latest]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Build with Maven
run: mvn clean install -DskipTests
- name: Login to docker hub
run: docker login -u "${{ secrets.DOCKER_USERNAME }}" -p "${{ secrets.DOCKER_PASSWORD }}"
- name: Build docker image
run: docker build -t <dockerhub repository name>.
- name: Push docker image
run: docker push <dockerhub repository name>:latest
deploy:
needs: build
runs-on: [<ec2 instance runner's lable>]
steps:
- name: Check Docker Installation
run: |
if ! [ -x "$(command -v docker)" ]; then
echo "Error: Docker is not installed." >&2
exit 1
fi
- name: Pull image from docker hub
run: sudo docker pull <dockerhub repository name>:latest
- name: Delete existing container
run: |
if [ "$(sudo docker ps -aq -f name=demo)" ]; then
sudo docker rm -f demo
fi
- name: Run docker container
run: sudo docker run -d -p 8080:8080 --name demo <dockerhub repository name>
ssh连接https://www.freebuf.com/articles/sectool/435623.html 和 https://github.com/appleboy/ssh-action/blob/master/README.zh-cn.md 以及 https://blog.gitcode.com/6676e2ca182e0fcb7d332c92dd2968c7.html
- name: Deploy blog.emooa.com
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "Removing /var/www/$USER_NAME/blog"
ssh $USER_NAME@$IP "rm -f /var/www/$USER_NAME/blog || echo 'no such directory.'"
echo "Creating /var/www/$USER_NAME/blog"
ssh $USER_NAME@$IP "mkdir -p /var/www/$USER_NAME/blog"
echo "Copying 'public' directory to /var/www/$USER_NAME/blog"
scp -r public/* $USER_NAME@$IP:/var/www/$USER_NAME/blog/
发布 https://github.com/marketplace/actions/upload-files-to-a-github-release
steps:
- name: Upload files to a GitHub release
uses: svenstaro/upload-release-action@2.9.0
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: path/to/your/asset.zip # The file to attach to the release
tag: ${{ github.ref }} # The tag associated with the release
steps:
- uses: actions/checkout@v4 # Checkout your repository code
- name: Build something
run: |
# Your build commands that generate the files you want to attach
echo "This is a test artifact." > my-artifact.txt
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: my-build-output # Name of the artifact
path: my-artifact.txt # Path to the file or directory to upload
name: Node.js CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'npm'
- run: npm install
- run: npm run build --if-present
- name: Upload a Build Artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download Build Artifact
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
自动发布的版本
draft: false
prerelease: false
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/your-executable
asset_name: your-executable
asset_content_type: application/octet-stream
k8s操作
https://spacelift.io/blog/github-actions-kubernetes#why-use-github-actions-for-kubernetes-deployments
https://github.com/actions-hub/kubectl