Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

update: workflow

update: workflow #19

Workflow file for this run

name: Build Docker Image & Pack Source Code
on:
push:
tags:
- 'v*'
# git tag -a v1.0.0
# git push origin v1.0.0
env:
IMAGE_NAME: baiduwp-php
jobs:
build_and_upload:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Parse version from tag name
run: echo "VERSION=$(echo $GITHUB_REF | sed -n 's/refs\/tags\/v\(.*\)/\1/p')" >> $GITHUB_ENV
- name: Build Docker image
run: docker build . --file Dockerfile --tag ${{ env.IMAGE_NAME }}
- name: Log into Docker Hub
run: echo "${{ secrets.DOCKER_ACCESS_TOKEN }}" | docker login -u yuantuo666 --password-stdin
- name: Push Docker image
run: |
IMAGE_ID=yuantuo666/$IMAGE_NAME
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=${{ env.VERSION }}
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
[ "$VERSION" != "latest" ] && docker tag $IMAGE_NAME $IMAGE_ID:latest
[ "$VERSION" != "latest" ] && docker push $IMAGE_ID:latest
- name: Run Docker image
run: docker run -itd --name baiduwp-php ${{ env.IMAGE_NAME }}
- name: Install zip
run: docker exec baiduwp-php apt-get update && docker exec baiduwp-php apt-get install -y zip
- name: Pack source code
run: docker exec baiduwp-php zip -r /tmp/baiduwp-php.zip /app
- name: Copy source code
run: docker cp baiduwp-php:/tmp/baiduwp-php.zip ./baiduwp-php-v${{ env.VERSION }}.zip
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.VERSION }}
release_name: Release v${{ env.VERSION }}
draft: true
prerelease: false
- name: Upload Release Asset
id: 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: ./baiduwp-php-v${{ env.VERSION }}.zip
asset_name: baiduwp-php-v${{ env.VERSION }}.zip
asset_content_type: application/x-zip-compressed