gitlab-go/.github/workflows/go-push.yml

352 lines
18 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Go Push
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ${{ matrix.os }}
env:
CGO_ENABLED: 0
RELEASE_BODY: 自动化发布
outputs:
YEAR_MONTH_DAY: ${{ steps.set_current_date_output.outputs.YEAR_MONTH_DAY }}
YEAR_MONTH_DAY_HOUR: ${{ steps.set_current_date_output.outputs.YEAR_MONTH_DAY_HOUR }}
YEAR_MONTH_DAY_HOUR_MINUTE: ${{ steps.set_current_date_output.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }}
RELEASE_BODY: ${{ env.RELEASE_BODY }}
strategy:
matrix:
os: [ "ubuntu-latest" ]
steps:
- name: Checkout repositoryxuxiaowei-com-cn/cicd-release
uses: actions/checkout@v4
with:
repository: 'xuxiaowei-com-cn/cicd-release'
- name: Set up Goxuxiaowei-com-cn/cicd-release
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Go Versionxuxiaowei-com-cn/cicd-release
run: go version
- name: Go Mod Downloadxuxiaowei-com-cn/cicd-release
run: go mod download
- name: Go Testxuxiaowei-com-cn/cicd-release
run: go test ./... -v
- name: Go Runxuxiaowei-com-cn/cicd-release
run: go run main.go
- name: Buildxuxiaowei-com-cn/cicd-release
run: |
go build -o buildinfo/buildinfo buildinfo/buildinfo.go
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$GITHUB_REF_NAME -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=linux/amd64 -X main.InstanceUrl=$GITHUB_SERVER_URL -X main.CiPipelineId=$GITHUB_RUN_ID -X main.CiJobId=$GITHUB_RUN_NUMBER" -trimpath -o cicd-release-linux-amd64 .
./cicd-release-linux-amd64 --version
./cicd-release-linux-amd64
- name: Upload Artifactsxuxiaowei-com-cn/cicd-release
uses: actions/upload-artifact@v3
with:
name: cicd-release
path: |
cicd-release-linux-amd64
- name: Checkout repository
uses: actions/checkout@v4
with:
# 获取所有的代码历史记录,包括分支和标签
fetch-depth: 0
#- name: Set up Go
# uses: actions/setup-go@v4
# with:
# go-version: '1.20'
- name: Set Current Date ENV
run: |
echo "YEAR_MONTH_DAY=$(date +'%Y-%m-%dZ')" >> $GITHUB_ENV
echo "YEAR_MONTH_DAY_HOUR=$(date +'%Y-%m-%dT%HZ')" >> $GITHUB_ENV
echo "YEAR_MONTH_DAY_HOUR_MINUTE=$(date +'%Y-%m-%dT%H-%MZ')" >> $GITHUB_ENV
- name: Get Current Date ENV
run: |
echo ${{ env.YEAR_MONTH_DAY }}
echo ${{ env.YEAR_MONTH_DAY_HOUR }}
echo ${{ env.YEAR_MONTH_DAY_HOUR_MINUTE }}
- name: Set Current Date OUTPUT
id: set_current_date_output
run: |
echo "YEAR_MONTH_DAY=${{ env.YEAR_MONTH_DAY }}" >> $GITHUB_OUTPUT
echo "YEAR_MONTH_DAY_HOUR=${{ env.YEAR_MONTH_DAY_HOUR }}" >> $GITHUB_OUTPUT
echo "YEAR_MONTH_DAY_HOUR_MINUTE=${{ env.YEAR_MONTH_DAY_HOUR_MINUTE }}" >> $GITHUB_OUTPUT
- name: Go Version
run: go version
- name: Go Mod Download
run: go mod download
- name: Go Test
run: go test ./... -v
- name: Go Run
run: go run main.go
- name: Git Tag
run: git tag v0.0.0-${{ env.YEAR_MONTH_DAY_HOUR_MINUTE }}
- name: Build
run: |
go build -o buildinfo/buildinfo buildinfo/buildinfo.go
GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$GITHUB_REF_NAME -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=windows/amd64 -X main.InstanceUrl=$GITHUB_SERVER_URL -X main.CiPipelineId=$GITHUB_RUN_ID -X main.CiJobId=$GITHUB_RUN_NUMBER" -trimpath -o gitlab-go-windows-amd64.exe .
GOOS=windows GOARCH=arm64 go build -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$GITHUB_REF_NAME -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=windows/arm64 -X main.InstanceUrl=$GITHUB_SERVER_URL -X main.CiPipelineId=$GITHUB_RUN_ID -X main.CiJobId=$GITHUB_RUN_NUMBER" -trimpath -o gitlab-go-windows-arm64.exe .
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$GITHUB_REF_NAME -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=linux/amd64 -X main.InstanceUrl=$GITHUB_SERVER_URL -X main.CiPipelineId=$GITHUB_RUN_ID -X main.CiJobId=$GITHUB_RUN_NUMBER" -trimpath -o gitlab-go-linux-amd64 .
GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$GITHUB_REF_NAME -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=linux/arm64 -X main.InstanceUrl=$GITHUB_SERVER_URL -X main.CiPipelineId=$GITHUB_RUN_ID -X main.CiJobId=$GITHUB_RUN_NUMBER" -trimpath -o gitlab-go-linux-arm64 .
GOOS=linux GOARCH=loong64 go build -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$GITHUB_REF_NAME -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=linux/arm64 -X main.InstanceUrl=$GITHUB_SERVER_URL -X main.CiPipelineId=$GITHUB_RUN_ID -X main.CiJobId=$GITHUB_RUN_NUMBER" -trimpath -o gitlab-go-loong64 .
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$GITHUB_REF_NAME -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=darwin/amd64 -X main.InstanceUrl=$GITHUB_SERVER_URL -X main.CiPipelineId=$GITHUB_RUN_ID -X main.CiJobId=$GITHUB_RUN_NUMBER" -trimpath -o gitlab-go-darwin-amd64 .
GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$GITHUB_REF_NAME -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=darwin/arm64 -X main.InstanceUrl=$GITHUB_SERVER_URL -X main.CiPipelineId=$GITHUB_RUN_ID -X main.CiJobId=$GITHUB_RUN_NUMBER" -trimpath -o gitlab-go-darwin-arm64 .
./gitlab-go-linux-amd64 --version
./gitlab-go-linux-amd64
- name: ls -l
run: ls -l
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: gitlab-go
path: |
gitlab-go-windows-amd64.exe
gitlab-go-windows-arm64.exe
gitlab-go-linux-amd64
gitlab-go-linux-arm64
gitlab-go-darwin-amd64
gitlab-go-darwin-arm64
gitlab-go-loong64
release-github:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# 获取所有的代码历史记录,包括分支和标签
fetch-depth: 0
- name: Download Artifactsxuxiaowei-com-cn/cicd-release
uses: actions/download-artifact@v3
with:
name: cicd-release
path: .
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: gitlab-go
path: .
- name: ls -l
run: ls -l
- name: chmod +x cicd-release-linux-amd64
run: chmod +x cicd-release-linux-amd64
- name: ls -l
run: ls -l
- name: Release GitHub
run: |
./cicd-release-linux-amd64 pre-release github --release-name=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --tag=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --auto-create-tag --github-repository=$GITHUB_REPOSITORY --github-username=$GITHUB_ACTOR --github-token=${{ secrets.PRIVATE_GITHUB_TOKEN }} --release-body=${{ needs.build.outputs.RELEASE_BODY }} --artifacts=gitlab-go-windows-amd64.exe --artifacts=gitlab-go-windows-arm64.exe --artifacts=gitlab-go-linux-amd64 --artifacts=gitlab-go-linux-arm64 --artifacts=gitlab-go-darwin-amd64 --artifacts=gitlab-go-darwin-arm64 --artifacts=gitlab-go-loong64
release-gitlab:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# 获取所有的代码历史记录,包括分支和标签
fetch-depth: 0
- name: Download Artifactsxuxiaowei-com-cn/cicd-release
uses: actions/download-artifact@v3
with:
name: cicd-release
path: .
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: gitlab-go
path: .
- name: ls -l
run: ls -l
- name: chmod +x cicd-release-linux-amd64
run: chmod +x cicd-release-linux-amd64
- name: ls -l
run: ls -l
- name: Release GitLab
run: |
./cicd-release-linux-amd64 pre-release gitlab --release-name=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --tag=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --auto-create-tag --gitlab-repository=$GITHUB_REPOSITORY --gitlab-username=$GITHUB_ACTOR --gitlab-token=${{ secrets.PRIVATE_GITLAB_TOKEN }} --release-body=${{ needs.build.outputs.RELEASE_BODY }} --package-name=cicd-release --artifacts=gitlab-go-windows-amd64.exe --artifacts=gitlab-go-windows-arm64.exe --artifacts=gitlab-go-linux-amd64 --artifacts=gitlab-go-linux-arm64 --artifacts=gitlab-go-darwin-amd64 --artifacts=gitlab-go-darwin-arm64 --artifacts=gitlab-go-loong64 --gitlab-export-assets-file-name=gitlab-release-assets.json
- name: Upload Artifactsgitlab-release-assets.json
uses: actions/upload-artifact@v3
with:
name: gitlab-release-assets
path: |
gitlab-release-assets.json
release-gitlink:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# 获取所有的代码历史记录,包括分支和标签
fetch-depth: 0
- name: Download Artifactsxuxiaowei-com-cn/cicd-release
uses: actions/download-artifact@v3
with:
name: cicd-release
path: .
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: gitlab-go
path: .
- name: ls -l
run: ls -l
- name: chmod +x cicd-release-linux-amd64
run: chmod +x cicd-release-linux-amd64
- name: ls -l
run: ls -l
- name: Release GitLink
run: |
./cicd-release-linux-amd64 pre-release gitlink --release-name=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --tag=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --auto-create-tag --gitlink-repository=$GITHUB_REPOSITORY --gitlink-username=${{ secrets.PRIVATE_GITLINK_USERNAME }} --gitlink-token=${{ secrets.PRIVATE_GITLINK_TOKEN }} --release-body=${{ needs.build.outputs.RELEASE_BODY }} --artifacts=gitlab-go-windows-amd64.exe --artifacts=gitlab-go-windows-arm64.exe --artifacts=gitlab-go-linux-amd64 --artifacts=gitlab-go-linux-arm64 --artifacts=gitlab-go-darwin-amd64 --artifacts=gitlab-go-darwin-arm64 --artifacts=gitlab-go-loong64 --gitlink-cookie=${{ secrets.PRIVATE_GITLINK_COOKIE }} --gitlink-export-assets-file-name=gitlink-release-assets.json
- name: Upload Artifactsgitlink-release-assets.json
uses: actions/upload-artifact@v3
with:
name: gitlink-release-assets
path: |
gitlink-release-assets.json
release-framagit:
needs:
- build
- release-gitlab
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# 获取所有的代码历史记录,包括分支和标签
fetch-depth: 0
- name: Download Artifactsxuxiaowei-com-cn/cicd-release
uses: actions/download-artifact@v3
with:
name: cicd-release
path: .
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: gitlab-go
path: .
- name: ls -l
run: ls -l
- name: chmod +x cicd-release-linux-amd64
run: chmod +x cicd-release-linux-amd64
- name: ls -l
run: ls -l
- name: Download Artifactsgitlab-release-assets.json
uses: actions/download-artifact@v3
with:
name: gitlab-release-assets
path: .
- name: Release FramaGit
run: |
./cicd-release-linux-amd64 pre-release gitlab --gitlab-instance=https://framagit.org --release-name=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --tag=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --auto-create-tag --gitlab-repository=$GITHUB_REPOSITORY --gitlab-username=xuxiaowei --gitlab-token=${{ secrets.PRIVATE_FRAMAGIT_TOKEN }} --release-body=${{ needs.build.outputs.RELEASE_BODY }} --gitlab-import-assets-file-name=gitlab-release-assets.json
release-gitee:
needs:
- build
- release-gitlink
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# 获取所有的代码历史记录,包括分支和标签
fetch-depth: 0
- name: Download Artifactsxuxiaowei-com-cn/cicd-release
uses: actions/download-artifact@v3
with:
name: cicd-release
path: .
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: gitlab-go
path: .
- name: ls -l
run: ls -l
- name: chmod +x cicd-release-linux-amd64
run: chmod +x cicd-release-linux-amd64
- name: ls -l
run: ls -l
- name: Download Artifactsgitlink-release-assets.json
uses: actions/download-artifact@v3
with:
name: gitlink-release-assets
path: .
- name: Release Gitee
run: |
./cicd-release-linux-amd64 pre-release gitee --release-name=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --tag=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --auto-create-tag --gitee-repository=$GITHUB_REPOSITORY --gitee-username=$GITHUB_ACTOR --gitee-token=${{ secrets.PRIVATE_GITEE_TOKEN }} --release-body=${{ needs.build.outputs.RELEASE_BODY }} --gitlink-export-assets-file-name=gitlink-release-assets.json