96 lines
2.6 KiB
YAML
96 lines
2.6 KiB
YAML
name: "Build {{project-name}}"
|
|
|
|
# You must add gitea secrets and enable actions for repository:
|
|
# CRATES_TOKEN
|
|
# DOCKER_USER
|
|
# DOCKER_PASSWORD
|
|
|
|
{%- if crate_type == "bin" %}
|
|
env:
|
|
DOCKER_REGISTRY: git.smetan.ru
|
|
IMAGE_NAME: "{{git-owner}}/{{project-name}}"
|
|
IMAGE_RELEASE_TAG: latest
|
|
IMAGE_PRE_RELEASE_TAG: pre-release
|
|
{%- endif %}
|
|
|
|
on:
|
|
{%- if crate_type == "bin" %}
|
|
push:
|
|
branches:
|
|
- master
|
|
- main
|
|
{%- endif %}
|
|
release:
|
|
types:
|
|
- published
|
|
|
|
jobs:
|
|
{%- if crate_type == "bin" -%}
|
|
{% raw %}
|
|
build_docker_app:
|
|
name: Build Docker Image
|
|
runs-on: docker-ubuntu-latest
|
|
steps:
|
|
- name: Checkout sources
|
|
uses: https://github.com/actions/checkout@v4
|
|
|
|
- name: Set Image Name
|
|
run: |
|
|
echo "Event type: $GITHUB_EVENT_NAME"
|
|
if [[ $GITHUB_EVENT_NAME == 'release' ]]; then
|
|
echo "IMAGE_TAG=$DOCKER_REGISTRY/$IMAGE_NAME:$IMAGE_RELEASE_TAG" >> "$GITHUB_ENV"
|
|
else
|
|
echo "IMAGE_TAG=$DOCKER_REGISTRY/$IMAGE_NAME:$IMAGE_PRE_RELEASE_TAG" >> "$GITHUB_ENV"
|
|
fi
|
|
cat $GITHUB_ENV
|
|
|
|
- name: Build Image
|
|
run: docker build --build-arg CRATES_TOKEN=${{ secrets.CRATES_TOKEN }} --file Dockerfile --tag ${{ env.IMAGE_TAG }} .
|
|
|
|
- name: Docker Login
|
|
run: docker login --username ${{ secrets.DOCKER_USER }} --password ${{ secrets.DOCKER_PASSWORD }} ${{ env.DOCKER_REGISTRY }}
|
|
|
|
- name: Push Image
|
|
run: docker push ${{ env.IMAGE_TAG }}
|
|
|
|
- name: Docker Logout
|
|
run: docker logout ${{ env.DOCKER_REGISTRY }}
|
|
{% endraw %}
|
|
{%- endif -%}
|
|
{%- if crate_type == "lib" -%}
|
|
{% raw %}
|
|
publish_crate_version:
|
|
name: Publish new crate version
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: git.smetan.ru/infra/ci-cargo:latest
|
|
credentials:
|
|
username: ${{ secrets.DOCKER_USER }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
steps:
|
|
- name: Checkout sources
|
|
uses: https://github.com/actions/checkout@v4
|
|
|
|
- name: Set cargo registry
|
|
run: |
|
|
cat <<"EOF" | tee ~/.cargo/config.toml
|
|
[registry]
|
|
global-credential-providers = ["cargo:token"]
|
|
EOF
|
|
|
|
- name: Set Cargo version
|
|
run: |
|
|
export VERSION=`sed 's/v//'<<<"${{ github.ref_name }}"`
|
|
echo "Set Cargo version: $VERSION"
|
|
sed -i "s/0.0.0-git/$VERSION/g" Cargo.toml
|
|
sed -i "s/0.0.0-git/$VERSION/g" Cargo.lock
|
|
|
|
- name: Publish package version
|
|
env:
|
|
{%- endraw %}
|
|
CARGO_REGISTRY: git_{{git-owner}}
|
|
{%- raw %}
|
|
run: cargo publish --registry $CARGO_REGISTRY --token "Bearer ${{ secrets.CRATES_TOKEN }}" --allow-dirty
|
|
{% endraw %}
|
|
{%- endif -%}
|