Update main.yml #30
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
# .github/workflows/deploy.yml | |
name: Deploy | |
on: | |
push: | |
branches: | |
- main | |
- development | |
- staging | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
environment: ${{ github.ref_name == 'main' && 'production' || github.ref_name }} | |
steps: | |
- name: Logging | |
run: | | |
echo "${{toJSON(github.event.commits[0].message)}}" | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Show variable | |
run: | | |
echo "Deploying the site: ${{ vars.APP_URL }}" | |
- name: Increment version from repository's tags | |
id: semver-tags | |
uses: SOLIDSoftworks/semver-tags@v1 | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
tag-prefix: 'stg-' | |
default-version: 'stg-0.0.0' | |
dry-run: true | |
- name: Create new tag | |
run: | | |
new_tag="stg-${{ steps.semver-tags.outputs.semantic-version }}" | |
echo "NEW_TAG=$new_tag" >> "$GITHUB_ENV" | |
git tag $new_tag | |
git push origin $new_tag | |
- name: Generate changelog | |
id: changelog | |
run: | | |
prev_tag="${{ steps.semver-tags.outputs.previous-version }}" | |
if git log --pretty=format:"%h - %s (%an, %ad)" "$prev_tag..HEAD" > changelog.txt 2>/dev/null; then | |
log=$(cat changelog.txt) | |
else | |
log="${{ github.event.commits[0].message }}" | |
fi | |
echo "body=$log" >> "$GITHUB_ENV" | |
- name: Create and publish release | |
id: create_release | |
uses: ncipollo/release-action@v1 | |
with: | |
name: "Staging release ${{ env.NEW_TAG }}" | |
body: ${{ env.body }} | |
tag: ${{ env.NEW_TAG }} | |
prerelease: true | |
- name: Deploy to ${{ github.ref_name }} environment | |
run: | | |
echo "Deploying to ${{ github.ref_name }} environment" | |
# Your deploy script/commands here |