Checkout and Create Release Version #271
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
push: | |
branches: | |
- master | |
schedule: | |
- cron: '0 1 * * *' | |
workflow_dispatch: | |
name: Checkout and Create Release Version | |
jobs: | |
check: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.get-version.outputs.version }} | |
build: ${{ steps.check-build.outputs.build }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Check Version | |
id: get-version | |
run: | | |
version=$(curl -s 'https://api.github.com/repos/1Panel-dev/1Panel/releases/latest' | jq -r ".tag_name") | |
echo "Current Version: ${version}" | |
if [ -z "${version}" ] || [ "${version}" == "null" ]; then | |
echo "Failed to get version" | |
exit 1 | |
fi | |
echo "version=${version}" >> $GITHUB_ENV | |
echo "version=${version}" >> $GITHUB_OUTPUT | |
- name: Check Release | |
id: check-release | |
run: | | |
gh release view ${{ env.version }} -R wojiushixiaobai/1Panel >/dev/null 2>&1 || echo "create=1" >> $GITHUB_OUTPUT | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Check Build | |
id: check-build | |
run: | | |
gh release view ${{ env.version }} -R wojiushixiaobai/1Panel | grep web-${{ env.version }}.tar.gz >/dev/null 2>&1 || echo "build=1" >> $GITHUB_OUTPUT | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Tag | |
run: | | |
sed -i "s@ARG VERSION=.*@ARG VERSION=${{ env.version }}@" Dockerfile | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add . | |
git commit -m "Release ${{ env.version }}" | |
git tag -a "${{ env.version }}" -m "Release ${{ env.version }}" || true | |
git push origin "${{ env.version }}" || true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Release | |
if: steps.check-release.outputs.create == 1 | |
run: | | |
gh release create ${{ env.version }} --notes "Release ${{ env.version }}" -R wojiushixiaobai/1Panel | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
release: | |
needs: check | |
runs-on: ubuntu-latest | |
if: needs.check.outputs.build == 1 | |
env: | |
version: ${{ needs.check.outputs.version }} | |
steps: | |
- name: Check Version | |
id: get-version | |
run: | | |
echo "Current Version: ${version}" | |
- name: Check Build | |
id: check-build | |
run: | | |
gh release view ${{ env.version }} -R wojiushixiaobai/1Panel | grep 1panel-${{ env.version }}-linux-amd64.tar.gz >/dev/null 2>&1 || echo "build=1" >> $GITHUB_OUTPUT | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
repository: 1Panel-dev/1Panel | |
ref: ${{ env.version }} | |
- name: Cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.npm | |
~/.cache | |
~/go/pkg/mod | |
key: ${{ runner.os }}-1panel-web-${{ github.sha }} | |
restore-keys: ${{ runner.os }}-1panel-web- | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Build Web | |
run: | | |
cd frontend && npm install && npm run build:pro | |
env: | |
NODE_OPTIONS: --max-old-space-size=8192 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 'stable' | |
- name: Get File | |
run: | | |
wget -O goreleaser.test https://github.com/${{ github.repository }}/raw/refs/heads/master/.goreleaser.yaml | |
- name: Build Binary | |
uses: goreleaser/goreleaser-action@v6 | |
with: | |
distribution: goreleaser | |
version: '~> v2' | |
args: release --config goreleaser.test --skip=publish --clean | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Make Files | |
run: | | |
mkdir -p build | |
mv cmd/server/web web-${{ env.version }} | |
tar -czf build/web-${{ env.version }}.tar.gz web-${{ env.version }} | |
echo "$(sha256sum build/web-${{ env.version }}.tar.gz | awk '{print $1}') web-${{ env.version }}.tar.gz" > build/web-${{ env.version }}.tar.gz.sha256 | |
- name: Upgrade Release | |
run: | | |
gh release upload ${{ env.version }} build/* -R ${{ github.repository }} | |
gh release upload ${{ env.version }} dist/*.tar.gz -R ${{ github.repository }} | |
gh release upload ${{ env.version }} dist/*.txt -R ${{ github.repository }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |