From e061b506d146525822516a42ad945aae225c9881 Mon Sep 17 00:00:00 2001 From: DG Date: Sat, 21 Aug 2021 14:21:38 -0400 Subject: [PATCH] Publish container to ghcr.io (#101) --- .github/workflows/ci.yml | 2 +- .github/workflows/docker.yml | 67 +++++++++++++++++++++++------------ .github/workflows/release.yml | 4 +++ Dockerfile | 2 +- github-action/Dockerfile | 2 +- src/rfd.rs | 4 +-- 6 files changed, 54 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db40159..9664cee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ # Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md -on: [push, pull_request] +on: [pull_request] name: ci diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 8e8fe53..bf27821 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,27 +1,50 @@ -name: Publish Docker image -on: - push: - tags: - - v* +name: Publish Container +on: [push] + jobs: push_to_registry: - name: Push Docker image to Docker Hub + name: Push to container registry runs-on: ubuntu-latest steps: - - name: Check out the repo - uses: actions/checkout@v2 - - name: Publish version to Registry - uses: elgohr/Publish-Docker-Github-Action@master - with: - name: davegallant/rfd-notify - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - tag_semver: true - - name: Publish latest to Registry - uses: elgohr/Publish-Docker-Github-Action@master - with: - name: davegallant/rfd-notify - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - tags: "latest" + - uses: actions/checkout@v2 + + - name: Prepare + id: prep + run: | + IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/rfd-notify + VERSION=${GITHUB_REF##*/} + + if [[ $GITHUB_REF == refs/heads/main ]]; then + VERSION=latest + fi + + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/v} + fi + + TAGS="${IMAGE_NAME}:${VERSION}" + + if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + TAGS="$TAGS,${IMAGE_NAME}:latest" + fi + + echo ::set-output name=tags::${TAGS} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Packages Docker Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Push to Packages + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.prep.outputs.tags }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5fdfd57..0be2385 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,10 +26,14 @@ jobs: - uses: hecrj/setup-rust-action@v1 with: rust-version: stable + - uses: actions/checkout@v1 + - name: Build run: cargo build --release --locked + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v1-release with: repo_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dockerfile b/Dockerfile index 41854bc..ba36a62 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust@sha256:b2fd2fcc9d28c1a6dc59c3b0b37913fd9a326c8e457e50617e1156fc1ad51e34 as build +FROM rust@sha256:f91b3dae52c0d99302366331e36cf6af8a923d36c68577df1f4d5a7c2721ca90 as build ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ diff --git a/github-action/Dockerfile b/github-action/Dockerfile index d1e6f64..ecf0bbf 100644 --- a/github-action/Dockerfile +++ b/github-action/Dockerfile @@ -1,3 +1,3 @@ -FROM davegallant/rfd-notify:0.2.0 +FROM ghcr.io/davegallant/rfd-notify:latest ENTRYPOINT ["/rfd-notify", "-c", "config.yaml"] diff --git a/src/rfd.rs b/src/rfd.rs index d81bf6f..fda32c8 100644 --- a/src/rfd.rs +++ b/src/rfd.rs @@ -59,7 +59,7 @@ pub async fn get_topic(topic_id: u32) -> Result Deals { - serde_json::from_str(&response).unwrap() + serde_json::from_str(response).unwrap() } pub fn parse_posts(response: String) -> Posts { @@ -89,7 +89,7 @@ pub fn match_deals(deals: Deals, config: Config, dbpath: &str) { ) } else if topic.offer.dealer_name.is_some() { let dealer_name = topic.offer.dealer_name.as_ref().unwrap(); - if re.is_match(&dealer_name) { + if re.is_match(dealer_name) { found_match = true; info!( "Expression '{}' matched dealer: {}",